use strict; my @chars = ("a".."z","A".."Z", 2..9); my $random_string = join("",@chars[map{ rand @chars} (1..8)]); #8 being the number of chars to randomize ofcourse print "$random_string\n";