use Sort::Fields; # sort on the second element (i.e. element #1) @sorted = fieldsort '\|', [1], @lines;