# The two arrays are in @arr1 and @arr2 my %hash; # loop over the arrays for (0..$#arr1) { # Add the value from arr2 to the approprate entry in # the hash $hash{$arr1[$_]} += $arr2[$_]; } foreach (keys(%hash)) { print "$_ $hash{$_}\n"; }