my $string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; my ($random) = $string =~ m/(??{'.'x rand length $string })(.)/s; print $random, "\n";