in reply to Re^4: Loop problem: jumps one record
in thread Loop problem: jumps one record

Just use the section name as the state flag...

#!/usr/bin/perl # http://perlmonks.org/?node_id=1180665 use strict; use warnings; my $section = ''; while(<DATA>) { if( /(.*)\(total: \d+\)/ ) # get section name { $section = $1; } elsif( $section =~ /Relay access denied/ and /^\s*\d+\s+(\S+)\s*$/ ) { print "$section $1\n"; # add $1 to DB one way } elsif( $section =~ /blocked using/ and /^\s*\d+\s+(\S+)\s*$/ ) { print "$section $1\n"; # add $1 to DB a different way } } __DATA__ Relay access denied (total: 13) 1 46.183.217.174 1 46.183.220.137 1 46.183.220.138 1 46.183.220.139 1 46.183.223.239 1 218.38.243.204 1 185.29.8.198 1 185.29.9.133 1 185.29.9.135 1 46.183.217.162 1 46.183.217.165 1 46.183.217.169 1 91.236.75.169 Sender address rejected: Access denied (total: 50) 1 77.236.75.169 blocked using dummy1 (total: 6) 3 rzxwrvxk.com 1 correio.biz 1 facebook.com 1 213.183.58.6 blocked using dummy2 (total: 330) 2 118.125.110.201 1 61.2.46.20 blocked using dummy3 (total: 5) 2 hinet.net 1 219.140.15.195 1 219.139.16.134 1 222.189.112.23 blocked using dummy4 (total: 53) 5 66.23.212.67 5 66.23.212.70 4 66.23.212.68 4 66.23.212.69 Relay access denied (total: 13) 1 46.183.217.174 1 46.183.220.137 1 46.183.220.138