#!/usr/bin/perl use strict; use warnings; # substituted for the FILE my @file2 = qw(789|efg|2222222 123|abc|9999999 786|uvw|1234567 123|xxx|0000000 234|cde|0000000 567|xyz|1111111); # process file 1 my %file_1_hash = (); while ( ) { chomp; my @array = split( /\|/ ); $file_1_hash{join( '|', @array[0..$#array-1] )} = $array[$#array]; } # when file2 is a FILE, just do a while loop here foreach (@file2) { my @file_2_array = split( /\|/ ); my $file_2_key = join( '|', @file_2_array[0..$#file_2_array-1] ); if ( !exists $file_1_hash{$file_2_key} ) { $file_1_hash{$file_2_key} = "NO MATCH"; } print join( '|', $file_2_key, $file_2_array[$#file_2_array], $file_1_hash{$file_2_key} ), "\n"; } __DATA__ 123|abc|777 234|cde|456 567|xyz|999