my $file = "output.txt"; open (FOO, "> $file") or die "Cannot write '$file': $!"; select(FOO); # Do stuff here during which default prints go to the file. # BUT: print STDOUT $string; will still go to STDOUT. It # isn't gone, just ignored by default. select(STDOUT); # If you are going to do a bunch more stuff. close (FOO); # prints here are back to normal.