Jun 7 13:47:56 smtpserver postfix/smtp[16346]: A9507208022: to=, relay=localhost[127.0.0.1], delay=0, status=sent (250 Ok: queued as B68C8208095) #### Jun 7 13:47:56 smtpserver postfix/smtpd[12725]: A9507208022: client=ourhost1.our.domain[172.111.111.111] #### Jun 7 13:47:57 smtpserver postfix/smtp[12379]: B68C8208095: to=, relay=server.somwhere.gov[10.0.100.100], delay=1, status=sent (250 ok: Message 2156237 accepted) #### foreach $line ( ) { if ( $line !~ /to=<.*(our\.domain)/i) { # our external domain is a subset of the ones we're looking for if ($line =~ /to=<.*\.gov>.*relay=localhost/i) { @ids = ($line =~ /\ ([0-9A-F]{11,12})/g); %msgids{$ids[0]} = $ids[1]; } } } open (FH2, $file ) or die "Cannot open file 2nd time: $!"; foreach $line ( ) { if ( $line !~ /client=(ourhost1|ourhost2)/ ) { foreach $keys (%msgids) { if ($key =~ /$line/) { delete $msgids $key; } } } # then do something to run through the log again and print # the delivery report line from the second msgid