use IO::Tee; my $tee = IO::Tee -> new(">stdout.txt", \*STDOUT); print $tee "Cheese!\n";