A modified version of your sample that does what I mean:
in reply to Re^2: Executing code block in memory
in thread Executing code block in memory
use CGI qw/:standard/;
use CGI::Carp 'fatalsToBrowser';
my $code = param('test');
$code = uri_unescape($code);
$code = encode_entities($code);
open STDERR, '>&STDOUT';
print $@ if $@;
No need to create external, temporary files. There are some potential messy issues in there, but this is good enough for rough cut.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.