#!C:/Perl/bin/perl.exe use strict; use warnings; my %keys = ( a => undef, e => undef, i => undef, o => undef, u => undef, ); my @records = qw{ 1|2|3|d|4 1|2|3|a|4 1|2|3|d|4 1|2|3|o|4 }; my @final = grep { my @flds = split '\|', $_; my $third = $flds[3]; exists $keys{$third} } @records; print "@final\n"; #### 1|2|3|a|4 1|2|3|o|4