Why would you select random characters with values ranging from 0 to 121 and later delete the ones that you didn't want to use in the first place, when you already know with which characters (the ones in the string $OK_CHARS) you want to build your random word?
You could just stick the characters you want to use in an array and pick the required number of random elements from the array, like so:
sub randomPassword {
my $length = shift || 12;
my @OK_CHARS = ('a'..'z', 'A'..'Z', '0'..'9', qw[_ - . @]);
my $password;
for (1 .. $length) {
$password .= $OK_CHARS[ int rand scalar @OK_CHARS ];
}
return $password;
}
— Arien