perl -Mstrict -wlne 'while(s/(\w+?)\1+//){print$`if$`;my@L=split"(?=$1)",$&;printf"%s repeated %i time%s\n",$1,$#L+1,$#L?"s":""}' #### while(s/(\w+?)(\1+)//) { print $` if $`; my @L = split "(?=$1)", $&; printf "%s repeated %i time%s\n", $1, $#L+1, $#L ? 's' : '' } #### perl -wlne 'while(s/(\w+?)\1+//){print$`if$`;@L=split"(?=$1)",$&;printf"%s repeated %i times\n",$1,$#L+1}'