use IO::Handle; my $captured = IO::Handle->new; tie *$captured, 'Capture::Handle', handle => $captured or die "Couldn't tie *CAPTURED: $!"; select CAPTURED; print .... my $captured = tied(*CAPTURED)->get_captured; package Capture::STDOUT; sub TIEHANDLE { my $class = shift; bless { @_ }, $class } sub set_handle { shift()->{'handle'} = shift } sub get_handle { shift()->{'handle'} } sub PRINT { my $self = shift; print $self->{'handle'} @_; push @{$self->{'captured'}}, @_; } sub get_captured { @{shift()->{'captured'}} }