I am unable to reproduce this effect.
The script below (slightly adapted from yours) runs just fine repeatedly
in the same session with expected results.
create or replace function plperl_bug1( )
returns text as
$$
my $qry = 'select * from pg_user';
elog NOTICE, "Good Query is: $qry";
my $rv =
--
-- An SQL error causes subsequent function creation of an otherwise
-- healthy function to fail WHEN RUN with:
--ERROR: creation of function failed:
--(in cleanup) Undefined subroutine &PLPerl::mksafefunc called at (eval 4) line 4.
--
-- Workaround is to close and reopen the connection