my $string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; my ($random) = $string =~ m/^ (??{'.{' . int(rand length $_) . '}' }) (.) /sx; print "$random\n";