Try changing your indices to run from 0 to 9, and see if that fixes the problem.
It's possible that the problem is that your array indices start at 1. The first index in a perl array is 0, so when you're sorting the array it could be tripping on the fact that $count[0] is empty.