# somewhere near the top of your code, put this: { package AccumHandle; sub TIEHANDLE { my( $pkg, $s ) = shift; bless \$s, $pkg } sub PRINT { my $self = shift; $$self .= join($,,@_).$\; } } # now do this where you call the subroutine: local ACC; tie *ACC, 'AccumHandle'; select ACC; &log(); select STDOUT; my $xx = ${tied(*ACC)}; print "$xx";