in reply to matching input to hash keys

foreach $_ (keys (%list)){ if (exists $list{$_}){
While not trying to correct your code, I'll suggest that this expression always returns true. A key in a hash always exists in the hash!

-- Randal L. Schwartz, Perl hacker