in reply to sort by field

Can this be done in perl?
Of course! Perl has a built-in sort function that allows you to supply a comparison function so you can specify how you want sorting to be done.
perldoc -f sort
For a more tutorial approach, see Randal's article on sorting, in which he introduces the Schwartzian Transform.

Caution: Contents may have been coded under pressure.