If the algorithm is exactly duplicated between Perl and Java, yes, Java is likely to win but C would beat them both. BUT the whole point of Perl is that it lends itself to creating more efficient algorithms easily and so much so that when approached properly, even C is likely to lose unless the C program is massive enough in its complexity to duplicate the terser optimal Perl algorithm. In this case, you are effectively processing all permutations instead of using any kind of sorting efficiency. Try to think of a way to represent the data so that as many losing iterations as possible simply aren't processed by an improved algorithm.