foreach $entry (@iplist) { chomp ($entry); eval { &SDM }; if($@) { # log the error open ( ERROR_LOG, ">>$dte-error.txt") or die "Could not open $dte-error.txt.\n"; print "$entry: failed with $@ !\n"; print ERROR_LOG "$entry: failed with $@ !\n"; close ERROR_LOG; } }