# $f1 - small file # $f2 - big file open my $fh, $f1 or die "cannot open $f1: $!\n"; my @file1 = <$fh>; my %file1 = map{ chomp and (join '|', (split /\|/)[0,1]), (join '|', (split /\|/)[2]) }@file1; open my $fh, $f2 or die "cannot open $f2: $!\n"; while(<$fh>){ chomp; my $part = (join '|', (split /\|/)[0,1]); print $_, '|', (exists $file1{$part} ? $file1{$part} : 'NO MATCH' ), $/; }