in reply to Case insensitive hash key existance

Probably $data{fc $str} (in every instance of using the hash key) if your Perl is new enough. $data{lc $str} otherwise. The later may come with surprises if you deal with "wide characters."