in reply to Finding a random position within a long string (Activeperl Build 822)

Here's another way that builds an array of random positions in which to place a '?' and then makes the substitutions using an array slice. Downside is the spliting and rejoining of the string.

use strict; use warnings; my $str = q{ABC} x 10_000; my @chars = split m{}, $str; my @randPosns = grep { rand 10 < 1 } 0 .. length($str) - 1; @chars[@randPosns] = (q{?}) x @randPosns; my $newStr = join q{}, @chars; print $newStr;

Cheers,

JohnGG