in reply to Redirecting STDOUT and standard error to file

It may be worthwhile to look into the script command:

script file.log perl -w sample1.pl 2>&1 echo $? exit col -b file.log > stdout.txt

Note -- script will save _everything_ that goes be the terminal into a file, which is why you need to pass it through col to get a more sane log file. It may be an advantage or disadvantage that everything gets saved, including subsequent commands, until you exit script.