use constant MIN_REPEATS => 2; # Must have at least this many repeats my $str = 'aabcdabcabcecdecd'; local our %counts; $str =~ /(.{2,})(?{ ++$counts{$1} })(?!)/s; delete @counts{ grep $counts{$_}