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


in reply to how do i redirect STDOUT, STDIN, or STDERR to a FILE?

The easist way to do this is to use fdopen from IO::Handle:
use IO::Handle; open INPUT, '<', "input.txt" or die $!; open OUTPUT, '>', "output.txt" or die $!; open ERROR, '>', "error.txt" or die $!; STDIN->fdopen( \*INPUT, 'r' ) or die $!; STDOUT->fdopen( \*OUTPUT, 'w' ) or die $!; STDERR->fdopen( \*ERROR, 'w' ) or die $!; # prints to output.txt: print "Hello Output File\n"; # reads everything from input.txt and prints it to output.txt: print <>; # prints to error.txt: warn "Hello Error File\n";