Now you changed your requirements in the middle - which incidentally is mostly annoying. If they're as in the OP, then my reply still applies.
Or else you will have to provide a suitable sort sub, possibly exploiting one of the various sorting techniques often references here and elsewhere. Try checking for example:
from the Tutorials section. A recent post of mine using a form of Guttman-Rossler is this. In this case you should have fixed length fields and it should be even easier for you to recover the original data with a single substr.