$i = 1; while ($i < $genome_length) { for ($j=1;$j<=6;$j++) { # run regexp looking for motifs of length $j # starting at position $i } $i = (end of previous match + 1) }