in reply to printing hash values and keys from user
Yes, it's because you are using a key that has a newline on it.
Try doing:
my $type = <stdin>; chomp $type; [download]
before using the key.