use Capture::Tiny ':all'; my ($stdout, $stderr, $exit) = capture { system( $program, $outfile ); }; print sprintf('Stderr: >%s< Stdout: >%s<', $stderr, $stdout); if ( $exit != 0 ) { die sprintf('%s exited with status %s.', $program, $exit; }