$code = <<'CODE'; print "Hello World!\n"; BEGIN {print '# hacked #';} CODE $code =~ s/BEGIN|CHECK|INIT|END//g; # kill blocks here $code = "{last; $code}"; # stop test code running eval $code; # now have a look see at $@ to see if it contains an error # due to the test code being invalid. print $@ ? "Invalid\n" : "Syntax OK\n";