my @ranges = ([a..z]) x 3, ([A..Z]) x 3, ([0..9]) x 3; my $password; while (@ranges) { $range = splice @ranges, rand @ranges, 1; # random pick $password .= $range->[rand @$range]; # random pick from the range }