http://www.perlmonks.org?node_id=22628


in reply to It's friday, I can't think.

If you are writing these subroutines yourself, you should just write to a filehandle. open it somewhere and then just
print FH $whatever;
If these are subroutines that someone else wrote, and you really don't want to edit them, you could do something like
open(FH, "output.txt"); my $oldfh = select(FH); sub_that_writes_to_file(); select $oldfh; # reset to whatever it was close FH;
This will work provided that the sub doesn't explicitly do print STDOUT.