in reply to Correct Loop Structure

After further consideration, if you're wanting to print up to 500 lines total for each unique IP#, you should try a hash instead of the array. Take a look at this:

open (LOG, "$fw_logfile") or die and mail_error($!); open (OUTFILE, "+>>$outfile") or die and mail_error($!); my %newIPseen; foreach my $i ( @newips ) { $newIPseen{$i} = 0; } while (<LOG>) { foreach $i ( keys( %newIPseen ) ){ unless ( $newIPseen{$i} == 500 ) { print OUTFILE if (/\;drop;[^"]*$i/) && $newIPseen{$i}++; } } }

Now, if you load the hash %newIPseen in the first place instead of the array @newips, you can get rid of the first foreach loop.