while() { my $source = $_; if($source =~ m/^(\s)*$/) { $source = for 1..2; } #Go through each line until you hit page 1 of sorter 2 if (substr($source,145,16) =~ /Page:\s*1/) { $source = for 1..2; if (substr($source,72,9) =~ /Sorter: 2/) { ++$dcount; printf LOGFILE $source; } } }