Can you please give a before/after data example of what you are trying to accomplish? Your question seems a little vague and your input data doesn't lend much help, as column #2 is (4,9) and looks to already be sorted correctly.
And yes - as previous poster indicated, "use strict;" and "use warnings;" should be in every Perl script.
column #2 is (4,9) and looks to already be sorted correctly
Off by one - index 2 is the third column, (5,10). Also the OP appears to want a reverse sort - at least I'm assuming that based on the $b being before $a and the OP saying the current code doesn't work.