in reply to Function over all letters in a string

This is close to what you said, but made it one liner:

use strict; use warnings; my $str = "cat"; print join("", map {$_ x (1 + rand(3))} split //, $str);