use IO::Scalar; my $output; tie (*STDOUT, 'IO::Scalar', \$output); # Use this to capture STDOUT print "testout\n"; untie *STDOUT; # Use this to return STDOUT to normal print "my output='$output'";