If you'd like to sort the testcases as well, then use a hash instead of an array in the first place. And DON'T call it %hash :), it's just not healthy. Let @array be %testcases instead.
You can then sort keys %testcases and process the embedded hashes as well.