in reply to Assigning Null to a variable
for (1..$length) { my $alphanumber .= $chars[int rand @chars]; } ^^ [download]
Most likely, your real problem is the above my ...