in reply to Using map and grep to Sort one list using another list

Interesting problem. Maybe you could do something with a hash for your keys? This doesn't completely match your spec, although it matches your example. Perhaps you can adapt this for your needs...
my %keys = ( a=>1, e=>2, i=>3, o=>4, u=>5, ); my @records = (); push @records, '1|2|3|d|4'; push @records, '1|2|3|a|4'; push @records, '1|2|3|d|4'; push @records, '1|2|3|o|4'; my @final = (); my @result = (); my $re = ''; map {my @flds=split /\|/; push @{$final[$keys{$flds[3]}||0]},$_} @reco +rds; # note that entry 0 is where the unmatched elements wind up... print map{ "@{ $final[$_] }\n" } grep defined $final[$_],1..$#final;
Maps used only for their side effects are kinda wierd, though. I'd replace the map with a foreach(@records) block so it's clearer what you're doing.
foreach(@records) { my @flds=split /\|/; push @{$final[$keys{$flds[3]}||0]},$_; }

Mike