# redirect STDOUT to stdout.log and capture STDERR in @out my @out = `/home/applications/samtools-0.1.7a/samtools view -bS $ARGV[0] 2>&1 1>stdout.log`; print OUT @out; my $stdout = do { local( @ARGV, $/ ) = 'stdout.log'; <> }; # slurp the contents of stdout.log into $stdout print $stdout;