my (@exists, @not_exists); push @{exists $order{$_} ? \@exists : \@not_exists }, $_ for @to_be_ordered; my @sorted = ((sort {$order{$a} <=> $order{$b}} @exists), @not_exists);