{ my $r = substr rand, 2; sub crand() { length $r or ($r = rand) =~ tr/0-9//cd; chop $r; } } s[(.)]{$1 x (1+crand/3)}ge;