http://www.perlmonks.org?node_id=998215


in reply to RegEx + vs. {1,}

my $string = 'abcdefgxxabcdefgzzabcdsjfhkdfab'; my %seen; 1 while $string =~ /(\w{2,}?)(?{$seen{$1}++})(?!)/g; print [sort { $seen{$b} <=> $seen{$a} || length($b) <=> length($a) } keys %seen]->[0];
Update: Thanks Athanasius for your appreciation && corrections.