use strict; use warnings; # Sample data my $catFile = < 1} <$catIn>; close $catIn; open my $dataIn, '<', \$dataFile; while (<$dataIn>) { chomp; my @parts = split /\|/; next unless exists $keys{$parts[1]}; print join ('|', @parts), "\n"; } close($dataIn); #### E|123|r|some|56|78|90 D|678|r|some|56|78|90 F|345|r|y|98|0|0