my @allowedchars = ('a'..'z',0..9,'A'..'Z'); for (1..8) { print $allowedchars[rand(scalar( @allowedchars - 1 ))]; }