in reply to Hash references?

my %$foo=("key1"=>"value1","key2"=>"value2");
I think you really want:
my %foo=("key1"=>...);
The difference is that $foo refers to the scalar variable whereas $foo{'key1'} accesses the hash %foo (with key key1).

If you want to create a reference to a hash, use curly braces:

my $hash_ref = { key1 => ... };
and then you access values in the hash with the -> operator, e.g. $hash_ref->{key1}.