my $test_output; my $test_err; tie(*STDOUT, 'IO::Scalar', \$test_output); tie(*STDERR, 'IO::Scalar', \$test_err); eval { runtests(@testfiles); }; $test_output .= $@ if ($@); untie(*STDOUT); untie(*STDERR); $test_output .= $test_err;