# at the start of cgi script my $output = ''; # to store the output. open SECOUT, ">&STDOUT"; tie *STDOUT, 'BLAH', $output; .... ...... .... # this is the last thing done before the script exits. open OUTFILE, ">>test.log" or die "Cannot open blah blah.. $!\n"; print OUTFILE "----\n", $output; close OUTFILE; print SECOUT $output; # reprint the output to real STDOUT ... .... .. # somewhere else. package BLAH; use Tie::Handle; my $data; sub TIEHANDLE { return bless {}, shift; } sub PRINT { my $self = shift; $data .= join '', @_; }