in reply to Sorting based on a specific order
Or even (no sorting, no array index arithmetic):
my %wanted = map { $_ => 1 } @unsorted; my @sorted = grep { $wanted{$_} } @preferred; [download]