use strict ; use warnings ; use Data::Dumper ; my %hash_origin = ( 'key1' => 1, 'key2' => 1, 'key3' => 1 ) ; my @keys = qw( key1 key1 key2 key2 key2 ) ; my %hash ; foreach ( @keys ) { my $key = $_ ; $hash{ $key } += $hash_origin{ $key } ; } print Dumper( \%hash ) ; __END__ $VAR1 = { 'key1' => 2, 'key2' => 3 };