Ups, you are right about sorting, corrected. And the rest depends on whether it is really golfing problem (
print better) or normal task/job (I would discuss here if really
printf is better in place where only new line 'must be achieved'. I prefer
print with
-l switch, but then of course the loop must be rewriten. And if it is perl 5.10, then we can even advice
perlfunc-> say() without rewriting loop)