open (TEXT, "sample.txt")||die"Cannot"; ... NEXTLINE: while ($count < 1000) { $line = ; $count++; foreach my $value (@regexes) { ... while ($line =~ /$value/g) { ... } ... } } ...