in reply to Output Formatting

I would build a hash of lists. The headers (containing column names?) would be the hash keys, and the values would be anonymous arrays constructed from each row. A list of lists would work too, if you are comfortable using column indexes instead of names.

When you extract columns, access the anonymous list (via index, in a list of lists or via column name in a hash of lists), do a simple sort on it, and you will have your data. See perldoc perldsc for information on how to build and to access complex data structures. You'll end up with something like:

my %columns = { "name" => [ 'bob', 'jim', 'fred' ], "age" => [ '23', '44', '54' ], "hair" => [ 'blond', 'brown', 'none' ] };