use IO::Scalar; tie *STDOUT, 'IO::Scalar', \$buffer; # all stdout will now go to $buffer, ie print "hello world"; untie *STDOUT; print "buffer is $buffer\n\n"