use strict;
use warnings;
use Data::Dumper;
my $file1 = 'file1';
my $file2 = 'file2';
#reading file1 into a hash
my %hash;
open (my $fh,'<',$file2) or die $!;
while(my $line=<$fh>)
{
chomp $line;
$hash{$line}=1;
print Dumper %hash;
}
close $fh;
#reading file2 line by line
open (my ($fh2),'<',$file1) or die $!;
while (my ($row) = <$fh2>) {
chomp $row;
# next if $row =~ /^\s*$/;
my (@fields) = split(/\|/, $row);
print $row if exists $hash{$fields[0]};
}
close $fh2;