my @result = map { my $key = $_; grep m/^\d\|\d\|\d\|$key\|\d$/, @records } @keys;