use strict; use warnings; open my $fh, ">test.out" or die "Can't open outfile."; print $_ "Test string.\n" for \*STDOUT, $fh; close $fh;