my $matchFound = 0; while ($currentfile=) { if( ! $matchFound ){ $matchFound = 1 if $currentfile =~ /^\d{6}/ && $search_date eq substr($currentfile,52,10); } next unless $matchFound; print RESULTS $currentfile; }