my $string = "TGAT"; my @nts = map { my $tmp = $string; substr $tmp, $_, 1, '.'; $tmp; } (0 .. length ($string) -1); my $groupings = join '|', @nts; my $sample = "TGATTGGAATGTTAGAT"; while ( $sample =~ /($groupings)/go ) { print "Matched $1 ending at position ", pos $sample, "\n"; }