sub kramba { my %count; my $count; $count = sub { my( $string) = @_; my $length = length( $string ); if ($length < MIN) { $count{$_} == 1 and delete $count{$_} for keys %count; return \%count; } for my $l (MIN..$length) { my $s = substr( $string, 0, $l ); $count{ $s } += 1; } $count->( substr( $string, 1 ) ); }; $count->(shift); for (keys %count) { delete $count{$_} unless $count{$_} >= 2 and length($_) >= MIN; } \%count; }