use strict; use warnings; open STDERR,">","$0.log" or die $!; ... ... warn "this goes to my log file"; ... print "but this doesn't\n"; ....