in reply to Re^2: force regular expression to match every item only once
in thread force regular expression to match every item only once

Based on my last code, you could add a hash with the number of occurrence of every pair and then check if this pair was already matched this often:
use strict; use warnings; my $word = "zezlze"; my $dictword = "zezezd"; my @pairs = $word =~ /(?=(..))/g; my %count; $count{$_}++ foreach (@pairs); my $matcher = qr/(?=(@{[join "|", @pairs]}))/; my %seen; my $matches = 0; my @matches; foreach my $match ($dictword =~ /$matcher/g) { if ($seen{$match}++ < $count{$match}) { $matches ++; push @matches, $match; } } print "Matches: @matches\n"; print "$matches $dictword \n";
results in
Matches: ze ez ze 3 zezezd