#!/usr/bin/env perl use strict; use warnings; use Data::Dump; my $h1 = {locset => [409], status => [501, 137]}; my $h2 = {status => [137, 124], locset => [405, 409], class => [0]}; my %seen = map { $_ => { map { $_ => 1 } @{$h1->{$_}} } } keys %$h1; my $x = $h1; for my $key (keys %$h2) { if (exists $seen{$key}) { push @{$x->{$key}}, grep { ! $seen{$key}{$_} } @{$h2->{$key}}; } else { $x->{$key} = $h2->{$key}; } } dd $x; #### { class => [0], locset => [409, 405], status => [501, 137, 124] }