my $sub = 'CGAGCGTTGACGCNNAGCTAGT'; my @bases = split //, $sub; my $count = 100; my $len = length $sub; @promoters_regex = ( qr'[NT][GCATN][NG][NC][NG][NT][NG]', qr'[NG][NT][NG][NC][NG][GCATN][NT]', qr'[NA][GCATN][NC][NG][NC][NA][NC]', qr'[NC][NA][NC][NG][NC][GCATN][NA]', ); my $permutations_total = 0; while ($count--) { my $ilen = $len; my $string; $string .= $bases[rand @bases] while $ilen--; foreach my $regex (@promoters_regex) { $permutations_totals += scalar($string =~ m/$regex/g); } }