QM’s approach is probably the best way to go. But, for completeness: another option is to use tee from the command line. The tee command allows standard output to go to the terminal as usual, while also copying it to one or more files:
perl program.pl | tee -a output.txt
Notes:
- The -a option appends to the file instead of overwriting it.
- You will also need to add the line:
$| = 1;
or its equivalent near the top of the Perl script to force a flush after every print statement (otherwise, you won’t see the Enter file name: prompt).
- tee is standard on Unix-based operating systems. If you’re on Windows, you can download it as part of the GnuWin CoreUtils package from SourceForge.
Hope that helps,