while(){ foreach my $i (@newips){ if (/\;drop;[^"]*$i/) { print OUTFILE for 1 .. 500; } } }