my %data_hash; open(my $fh, '<', "datafile.txt") or die $!; while(<$fh>){ $data_hash{$_} = 1; } close($fh); open(my $fh1, '<', "tmpfile.txt") or die $!; while(){ if(defined($data_hash{$_})){ print"Line match"; }else{ print"Line not match"; } } close($fh2); close($fh1);