close(STDOUT); close(STDERR); open(STDOUT , ">logfile.txt") or die "Can't open logfile: $!\n"; # now anything that is printed will go to the logfile unless # its given another filehandle. Just be sure to close the # handle before the program exits. ... # program end close(STDOUT);