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