#my @chars = grep !$seen{$_}++, $text =~ /./g; my @chars = 'a'..'z'; my ($re) = map qr/$_/, join '|', map "${_}{4,}", map quotemeta, @chars; $text =~ s/($re)/substr($1,0,3)/eg;