in reply to first elements in array, split join and sort problem

This might help (will ignore empty lines if they exist):

push(@lines, \@line) if @line;