my @strs = qw/fooxx baryyyy bazzzzzzz/; s{ ( (.) \2+ ) \z }(substr($1, 0, length($1) / 2))ex, print for @strs; __output__ foox baryy bazaaa #### reverse =~ /\A((.)\2+)/ and substr($_, -(length($1) / 2)) = '' for @strs; print map "$_\n", @strs; __output__ foox baryy bazaaa