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;