Are all the numbers zero padded to the same length?? Then see my answer below but use the default sort instead of the
numeric sort in both places. The first numeric sort is 'numerifying' the strings and stripping the leading zeroes which messes up the rest of the routine.
Update: Ok, its not necessarily the first sort stripping the zeroes (in my test case, I was doing a numeric sort before I called the sub, so that's what I was seeing), but it does cause the subsequent statements to treat the list as numbers instead of character
strings. So you should treat them as either numbers or characters throughout the sub (like using the +0 trick to begin with), but not both.