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);