in reply to Assigning Null to a variable

for (1..$length) { my $alphanumber .= $chars[int rand @chars]; } ^^

Most likely, your real problem is the above my ...