#! /usr/bin/perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Sortkeys = 1; my $in1 = 'data1.txt'; my $in2 = 'data2.txt'; my %hash1 = map { chomp; split m{;}, $_, 2 } grep { ! /^Kuerzel/ } do { open my $fh, '<', $in1; <$fh> }; my %hash2 = map { chomp; split m{;}, $_, 2 } grep { ! /^Kuerzel/ } do { open my $fh, '<', $in2; <$fh> }; my %result = ( %hash1, %hash2 ); # identify uniq entries # grep all keys from hash1 which are not in hash2, and vice versa # take the resulting lists of the two greps and use their values as hash keys for a new hash my %single = map { $_ => 1 } ( grep { !exists $hash2{$_} } keys %hash1 ), ( grep { !exists $hash1{$_} } keys %hash2 ); # as alternative use two for-loops and iterate through keys of each hash and set each key individually # for my $k ( keys %hash1 ) { # $single{$k}++ if not exists $hash2{$k}; #} #for my $k ( keys %hash2 ) { # $single{$k}++ if not exists $hash1{$k}; #} print Dumper( \%hash1, \%hash2, \%result, \%single ); __END__ * result (with comments): # hash1 (from data1.txt) $VAR1 = { 'ABC' => 'abc', 'DEF' => 'def', 'GHI' => 'ghi' }; # hash2 (from data2.txt) $VAR2 = { 'ABC' => '123', 'JKL' => 'jkl' }; # result (combination of hash1 and hash2) $VAR3 = { 'ABC' => '123', 'DEF' => 'def', 'GHI' => 'ghi', 'JKL' => 'jkl' }; # single ( all uniq keys from both hashes) $VAR4 = { 'DEF' => 1, 'GHI' => 1, 'JKL' => 1 };