in reply to sorting very large text files

Stick with the system sort. It does what needs to be done to not use too much memory, and this is why it's slow.  The system sort already is optimised C code — don't expect a functionally equivalent Perl solution to be faster for this particular task.