in reply to Returning an array the way it was written

That doesn't look like Perl code.

In Perl the whole point of an array is that it maintains order.

my @x = (3, 1, 2); print "@x";
Output:
3 1 2


The way forward always starts with a minimal test.