in reply to Sorting an array by another array

my @sortme = qw(a b c d); my @order = qw(d c e f); my %sortme; @sortme{@sortme}=(); my %order; @order{@order}=(); my @sorted = (grep(exists $sortme{$_}, @order), sort grep !exists $order{$_}, @sortme) ); print "$_\n" for @sorted;