or download this
my $line1 = 'Oct 9 08:50:53 mail_server sendmail[30172]: j99FopoN0301
+72: from=<support@symantec.com>, size=0, class=0, nrcpts=0, proto=ESM
+TP, daemon=MTA, relay=[218.1.114.182]';
my $line2 = 'Oct 9 04:20:35 mail_server sendmail[20773]: j975sOqf0323
+12: to=<522-2204194-1-13-51954mpxas@dimexpress.com>, delay=2+05:26:11
+, xdelay=00:00:00, mailer=esmtp, pri=19293815, relay=mail.xpress.com'
+;
...
if ($line2 =~ /relay=\[?(.*?)\]?$/) {
print $1, "\n";
}