in reply to retrieving in the correct order

A possible way is to build a hash of the first array, where the key is the id of the element.

If that's done you can easily use a hash slice to get an array with the values in the order of the second array.