in reply to running string as perl script and pass into STDIN programatically
I think that this will run your Perl code with STDIN fed and STDOUT/STDERR catched properly:
use IPC::Run 'run'; my ($stdout, $stderr); run [ qw/perl -e/, $code ], '<', \$args, '>>', \$stdout, '2>>', \$stde +rr;
Example run:
$ perl my $code = q[use feature 'say'; say for 1..10; warn 'zzz'; $z = <STDIN +>; $z=~y/a-z/A-Z/; say $z]; my $args = q[this is STDIN, why not?]; use IPC::Run 'run'; my ($stdout, $stderr); run [ qw/perl -e/, $code ], '<', \$args, '>>', \$stdout, '2>>', \$stde +rr; print "STDOUT: $stdout\n"; print "STDERR: $stderr\n"; __END__ STDOUT: 1 2 3 4 5 6 7 8 9 10 THIS IS STDIN, WHY NOT? STDERR: zzz at -e line 1.
__DATA__ will be broken unless you use real files instead of -e 'code' above. Feeding the code to STDIN (with "\n__END__\n" between the code and actual STDIN) may also work, but can break in strange ways with syntax errors in code.
Sorry if my advice was wrong.
In Section
Seekers of Perl Wisdom