sub rndStr{ # When an array is interpolated in a string $" is used to seperate the values # By setting it (locally) to '', we ensure that the string doesn't have spaces or # anything else inserted between the characters. local $" = ''; my ( $len, @chars_to_pick_from) = @_; # @picks will end up with as many random values as requested. my @picks = map{ # Generate random numbers bewteen 0 and # the number of chars supplied to pick from rand $#chars_to_pick_from # do it as many times as request } 1 .. $length; # Using an array slice interpolated in quotes to construct the string # @picks contains the random indices, the slice picks them out of the # array of choices past in. The resultant string is returned as a scalar. "@chars_to_pick_from[@picks]"; }