#!/usr/bin/perl -w use strict; while () { chomp; $_ =~ s/(\w)(\1+)/\($1$2\)/g; print "$_\n"; } __DATA__ thhheeee good boyy the qqquick brrrowwwn fooox #### t(hhh)(eeee) g(oo)d bo(yy) the (qqq)uick b(rrr)o(www)n f(ooo)x