use strict; use warnings; use constant { FILE_A => './kma', FILE_B => './kma2', }; my %a_hash; my @a_array; my @b_array; open my $a_fh, "<", FILE_A; while ( my $line ~= <$a_fh> ) { chomp $line; $line = /^(.+?);/; # This strips the first field from the line $a_hash{$1} = 1; # Now, I'll use the first field as my index to my hash push @a_array, $line; # This adds the line to the end of the array } close $a_fh; open my $b_fh, "<", FILE_B; while ( my $line = <$b_fh> ) { $line ~= /^(.+?);/; if ( not exists $a_hash{$1} ) { push @b_array, $line; } } close $b_fh; my @combined_array = sort (@a_array, @b_array); print "content of my combined array = @combined_array";