I am executing a Perl program. Whatever is being printed on my console, I want to redirect that to a text file.
If you want your output to be printed on console as well as logs then append this line to you code (e.g. before any print statements)
open (STDOUT, "| tee -ai logs.txt");
print "It Works!";
After last print in your script
close (STDOUT);
For error messages only,
open (STDERR, "| tee -ai errorlogs.txt");