my @indicies = sort { $list[$a] cmp $list[$b] } 0..$#list; my @rearranged; @rearranged[@indicies] = sort @list2;