my $s='helloworldhellohellohihellohiworld'; #determine every substring in the original my %hash; for my $i (0..length($s)-1) { $hash{substr($s,$i,$_)}++ for (1..length($s)-$i); } #filter out singles and the chars %hash=map { ($hash{$_}>1 && length($_)>1) ? ($_,$hash{$_}) :() } keys %hash; #yes this is how i format maps #and ternary ops.. :-) #print the results use Data::Dumper; print Dumper(\%hash); #### el,ell,ello,elloh,ellohi, he,hel,hell,hello,helloh,hellohi,hi, ld,ll,llo,lloh,llohi,lo,loh,lohi, oh,ohi,or,orl,orld, rl,rld,wo,wor,worl,world