in reply to system stdout redirected ok to a file but not to a variable.

In case the "Capture::Tiny" thing suggested above doesn't work for you, the next thing I'd suggest is to just ditch all the manipulations of STDOUT and STDERR in the perl script, add suitable redirection tokens to the shell command that you pass to system(), and then open and read the files that were created by the system call:
my $cmdout = "/tmp/cmd.stdout.$$"; my $cmderr = "/tmp/cmd.stderr.$$"; system( "my_special_command > $cmdout 2> $cmderr" ); my $exitcode = ( $? >> 8 ); for my $log ( $cmdout, $cmderr ) { open( my $logfh, "<", $log ) or die "WTF? $!"; local $/; my $logdata = <$logfh>; # now what? } unlink $cmdout, $cmderr;
(not tested)