my %hash; $hash{$_->{id}} += $_->{value} for @$var; $var = [ map { +{id => $_, value => $hash{$_} } } sort keys %hash ];