http://qs1969.pair.com?node_id=871546


in reply to Ignore Case when comparing Hash Keys

exists can only do case sensitive comparisons. Instead of doing exists, extract the keys from both hashes using keys, and then lower case them both before comparison:

Note: this solution preserves the case in both hashes by storing keys in a temporary third hash.

# make temporary hash using lower case keys only # hash allows for fast lookup of matching key later on in # our for loop my %hashLowercaseKeys1 = ( map { lc($_) => 1 } keys %hash1 ); foreach my $k (keys %hash2) { if (exists $hashLowercaseKeys1{lc($k)}) { print "$k: matched\n"; } else { print "$k: no match\n"; } }