use strict; use warnings; my $word = "zezl"; my $dictword = "zezezl"; my @pairs = $word =~ /(?=(..))/g; my $matcher = qr/(?=(@{[join "|", @pairs]}))/; my %seen; my $matches = 0; my @matches; foreach my $match ($dictword =~ /$matcher/g) { if (not exists $seen{$match}) { $matches ++; push @matches, $match; } $seen{$match} = 1; } print "Matches: @matches\n"; print "$matches $dictword \n";