my @list = sort keys %Commands; $colwidth = length((sort {length($b) <=> length($a)} @list)[0] ) +1; $ncol = int( $Users{$userid}{'screenwidth'}/$colwidth ); $nrow = int( scalar(@list) / $ncol ); $nrow++ if ( scalar(@list) % $ncol ); $fmt = "%-${colwidth}s"; foreach my $r ( 0 .. $nrow-1 ) { my $ind = @help; $help[$ind] = ''; foreach my $c ( 0 .. $ncol-1 ) { my $i = $c * $nrow + $r; $help[$ind] .= sprintf( $fmt, $list[$i] ) if($list[$i]); } }