use IO::Scalar; tie *STDOUT, 'IO::Scalar', \$a; # do STDOUT-specific code here untie *STDOUT; # and now do something interesting with $a