$net="192.168.4."; $counter=10; ... $ip=$net.$counter; ... while ( $counter <= 14 ) { ... open(LOGF,">>",$logpath . $ip); ... while ( ) { ... $ip=$net.$counter; ... } } $counter++; } #### my $net = "192.168.4."; ... for my $counter ( 10 .. 14 ) { my $ip = $net . $counter; ... open(LOGF,">>",$logpath . $ip); ... while ( ) { ... } } } #### $|++; #### @array = split(" ",); #### @array = split; #### #Only grab things associated with the current searched for ip and ends with .com .net and so on if (($array[7] =~ /[com|org|net|gov|cc|mil]\/$/)&&($array[3] eq $ip)) {