my $content; tie *STDOUT, 'IO::Scalar', \$content; do $file; untie *STDOUT; return $content; #### tie(*CAPTURE, 'IO::Scalar', \$content); select(CAPTURE); $| = 1; do $file; select(STDOUT); untie(*CAPTURE); return $content;