use strict; use warnings; my $cmd = 'perl -le "print qq{to stdout};print STDERR qq{to stderr};exit 42"'; my $cmdhack = qq{cmd /d/c $cmd 2>&1}; # works # my $cmdhack = qq{cmd /d/c "$cmd" 2>&1}; # also works (despite bizarre quoting) print "run:$cmdhack:\n"; my $out = `$cmdhack`; my $rc = $? >> 8; print "rc=$rc, stdout/stderr of command follows:\n"; print $out;