use IO::Tee; my $outfile = "test.out"; # Traditional approach: #open STDOUT, "|tee '$outfile'" or # die "Couldn't tee STDOUT to log file '$outfile': $!"; # Possible alternative? open STDOUT2, ">&=STDOUT" or die "Failed to alias STDOUT: $!"; *STDOUT = IO::Tee->new(\*STDOUT2, ">$outfile") or die "Failed to tee to aliased STDOUT and '$outfile': $!"; print "Test 1.\n"; system("echo Test 2."); # Don't really care that this isn't recorded