in reply to Why are my hash keys undefined?

Try replacing:
chomp $line;
with:
$line =~ s/[\r\n]+//g;
It might solve your problem if it is related, as I suspect, with line endings.