# print messages to both console and logfile sub PrintLogCon { print @_; print(LOG @_) or die "Error printing to $logfile: $!"; } #### use warnings; use strict; open(LOG, ">$logfile") or die "Error opening $logfile: $!"; ... ... ... do->stuff; do->it(again) or PrintLogCon("Error: $!"); do->stuff(more); ... ... ... close LOG or die "Error closing $logfile: $!"; __END__