my %where; map {$where{$_} = 1} keys %firsthash; map {$where{$_} += 10} keys %secondhash; foreach (keys %where) { print "$_: first list only\n" if $where{$_} == 1; print "$_: second list only\n" if $where{$_} == 10; }