# adapted from the Perl Cookbook, 16.9 @all = `( cmd | perl -pe "s/^/stdout: /" ) 2>&1`; for (@all) { push @{ s/stdout: // ? \@out : \@err }, $_ }