in reply to Confusion due to hash

Okay, well the approach I would take is to create a new hash where the keys/values of your existing hash are reversed.

You simply iterate through you existing hash and build up the new hash as you go, like so:

foreach my $key (keys %hash) { $newhash{$hash{$key}} += $key; }
Using your sample data, that will give you something that looks like:
%newhash = ( '1' => 40, '2' => 60 );
Does this help?

Cheers,
Darren :)