#!/usr/bin/perl use strict; use warnings; open my $oldout, '>&', STDOUT or die "Can't dup STDOUT: $!"; my $stream; close STDOUT; open STDOUT, '>', \$stream or die "Can't open STDOUT: $!"; print "Hello!\n"; $stream .= "This line is new!\n"; print $oldout $stream;