use strict; my @set_of_stuff = (1,3,4,6,7,8,10,12,13,14,15,19,23); my $items_per_row = 4; my @table_data; for (0 .. scalar @set_of_stuff / $items_per_row) { my @row_data = map {$_={cell_data=>$_ }} splice(@set_of_stuff,0,$items_per_row); push @row_data, {cell_data=>' '} while scalar @row_data < $items_per_row; push @table_data, { row_data => \@row_data }; } #### use HTML::Template; my $template = q{
}; my $template = HTML::Template->new(scalarref => \$template, option => 'value'); $template->param(table_data => \@table_data); print $template->output();