$threshold = "N" # see description above for($i=1;$i<=6;$i++) { my $pattern = "." x $i; while ($sequence_string =~ /($pattern)\1{$threshold,}/g) { .... } }