in reply to Sorting problem

Update: I missed "Order of those objects is related to its distance. Therefore O3 is closer to O1 then to O5.", sorry.

Basically, you are given a graph by its set of edges. I changed the input to

O1 O3 O5 O11 O73 O2 O72 O54 O12 O7 O3 O1 O6 O5 O12 O5 O1 O3 O6 O3 O7 O2 O11 O1 O12 O2 O3 O54 O2 O72 O2 O73 O1
You can visualize the graph in Graphviz:
print "strict graph {\n"; while (<DATA>) { my ($node, @neighbours) = split; print " $node -- $_\n" for @neighbours; } print "}\n";

Now, you want to turn in into a weighted graph. The original edges will have weight 1. Any combination of two edges (e.g. 01 -- 072) will have weight 2, and so on. Then, you are just searching for the lightest path that visits all the nodes. You did not specify in what node to start.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ