my $hash; foreach my $href (@ary_of_hrefs) { my $id_1 = delete $href->{id_1}; my $id_2 = delete $href->{id_2}; $hash->{$id_1}->{$id_2} = $href; }