use strict; use warnings; my $str = "Foooboooobaaar"; $str =~ s/(.)\1+/$1*/g; print "\n$str"; #### Fo*bo*ba*r