# open the file open my $fh, '<', 'myfile.dat' or die "$!" # translate the data into a 2D array my @rows = map [ split /\s+/ ], <$fh>; # sort on any column my @sorted = sort { $a->[1] cmp $b->[1] } @rows; # print the result print "@$_\n" for @sorted;