I am executing a Perl program. Whatever is being printed on my console, I want to redirect that to a text file.
In the CLI you can use >, like this:
perl script_name.pl > path_to_your_file
If you want to do this inside the perl script, add this code before you print anything:
open(FH, '>', 'path_to_your_file') or die "cannot open file";
select FH;
# ...
# ... everything you print should be redirected to your file
# ...
close FH; # in the end