use Data::Diver qw{ DiveVal }; my %hash; DiveVal(\%hash, @$_{qw{ id_1 id_2 }}) = $_->{v} for @aoh;