my $oldfh = select STDOUT; my $out = IO::File->new('output.txt', 'w',) or die $!; select $out; # Do something involving print(). It will go to output.txt. # Be nice and give back STDOUT select $oldfh;