http://qs321.pair.com?node_id=11121793


in reply to Re: regex, find words that occur more than once.
in thread regex, find words that occur more than once.

Good synthesis, as GrandFather says. A couple of minor stylistic elements you might consider: Full version with suggested modifications:
use strict; use warnings; use 5.10.0; my %reps; my $text = "and him him lad has him done and john has has"; while($text =~ /\b(\w+)\b(?=.*\b\1\b)/g){ $reps{$1} //= 1; $reps{$1}++; } foreach my $key (keys %words){ say "$key: $reps{$key}"; }

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.