use List::Util qw//; while (<>) { s {\b(\w)(\w*)(\w)\b} {$1 . join ("", List::Util::shuffle (split //, $2)) . $3}eg; print; }