my $found_date = 0; LINE: while ($currentfile=) { if (!$found_date and $currentfile =~ /^\d{6}/){ $match_date = substr($currentfile,52,10); if ($search_date eq $match_date) { $found_date = 1; } } next unless $found_date; print RESULTS "$currentfile"; }