 <p>Merging all the arrays together isn't necessary. Use <code>sort</code> to get the correct index ordering for the elements in <code>@x</code>:</p> <pre><code>@sort_by_x = sort { $x[$a] &lt;=&gt; $x[$b] } 0 .. $#x; # ==&gt; (0, 2, 1) </code></pre> <p>Then apply that index ordering to any other array:</p> <pre><code>@x = @x[@sort_by_x]; @y = @y[@sort_by_x]; @z = @z[@sort_by_x]; </code></pre>