I tried this but I dont think its everything you were talking about:
#!/usr/bin/perl -w
use URI::Escape;
use HTML::Entities;
use CGI qw/:standard/;
print "Content-type: text/html\n\n";
my $file;
if(param('test')){
my $code = param('test');
$code = uri_unescape($code);
$code = encode_entities($code);
open STDERR, '>&STDOUT';
open my $fh, '>', \$file;
print $fh $code;
close $fh;
open my $pipe, '-|', "perl -w $file";
close $pipe;
close STDERR;
}
The output I get with this is:
sh: -c: line 0: syntax error near unexpected token `;;'
sh: -c: line 0: `perl -w print "hi";'
This is what is passed to the script:
print "hi";
print "hello world\n";