#!perl use warnings; use strict; my $criteria; while (<>) { next unless /\S/; # skip blank lines if (/(Relay access denied|blocked using)/){ $criteria = $1; next; } if (/\d+\s+(\S+)/ && defined $criteria){ print "update db $criteria = $1\n"; } else { $criteria = undef; } }