use strict; use warnings; open FILE1, '<', 'file1.txt' or die ($!); open FILE2, '<', 'file2.txt' or die ($!); #- my %file1 = map { split '\|', $_ } ; my %file1 = map { chomp && s/\|$//g && split '\|', $_, 2 } ; #- my %file2 = map { split '\|', $_ } ; my %file2 = map { chomp && s/\|$//g && split '\|', $_, 2 } ; ## we now have A1=>'dog' in one hash, and A1=>'Fido' in the other close FILE1; close FILE2; open FILE3, '>', 'file3.txt' or die ($!); for (sort keys %file1) { print FILE3 join('|',$_,$file1{$_},$file2{$_}),'|',"\n"; } close FILE3; #### my %file1; while () { chomp; s/\|[\s]*$//; my ($key, $val) = split '\|', $_, 2; $file1{$key} = $val; }