#!/usr/bin/perl use v5.10; use strict; use warnings; sub tranpose(@); my @row; my @sorted; while(my $line = ) { push @row, [split(/\s+/,$line)]; } @sorted = map { my $in = $_; [map {sprintf("%6s",$_)} @$in]; } #Reformat before print tranpose #tranpose back to original form map {[sort {$a <=> $b} @$_]} #sort each column tranpose @row; map {print @$_,"\n"} @sorted; sub tranpose(@) { my @out; foreach my $j (0..$#{$_[0]}) { push @out, [map {$_[$_][$j]} (0..$#_)]; } @out; } __DATA__ 1014 1 10 1015 51 100 1016 11 50 1017 101 999