open(PCC_ERR, "ErrLog.PCC") or die "Cannot open ErrLog.PCC"; #PCC_ERR is the filehandle. Opens error log use Date::Calc(Today); # needed for calculating 'friendly' dates ($year, $month, $day) = Today; # Go through each line of the error log and only report if a line contains today's date and error codes 3022 or 3186 for $line () { if ($line =~ /$month-$day-$year/ && $line =~/3022|3186/) { use Net::SMTP; # If the condition is met, send an email with error message $smtp = Net::SMTP->new('smtp.server'); # connect to an SMTP server $smtp->mail('email.address'); # use the sender's address here $smtp->to('recipient.address'); # recipient's address $smtp->data(); # Start the email $smtp->datasend("To: recipient.address\n"); $smtp->datasend("From: email.address\n"); $smtp->datasend("\n"); $smtp->datasend("Error Report for $month-$day-$year: Errors Found on Server!\n"); $smtp->dataend(); # Finish sending the mail $smtp->quit; # Close the SMTP connection last; # break loop if error found } } close(PCC_ERR);