#!/usr/bin/perl use warnings; use strict; use Inline::Files; my %File1Hash; while (my $line = ) { next if $line =~ /^\s*$/; # skip blank lines $line =~ s/\s*$//; # remove all trailing space, # including the line ending $File1Hash{$line}++; } while (my $line = ) { next if $line =~ /^\s*$/; # skip blank lines my ($id) = split /\|/,$line; # get the first field print $line if exists $File1Hash{$id}; } =Prints COA213345|a|b|c| COA213345|a|b|c| =cut __FILE1__ COA213345 COA213345 COA213445 DOB213345 EOA213345 __FILE2__ COA213345|a|b|c| COA213345|a|b|c| LOA213345|a|b|c| kOB213345|a|b|c| LOA213345|a|b|c|