my $productcount = 0;#index of which product we are using print $q->table({-border=>1}); foreach (@champarray){# go through each item. my @rows; my @tmp_row_items = $q->p($champarray[$productcount][0]);#item 0 in array is the name of our item my $itemnum = $#{$champarray[$productcount]}; my $rownum = ceil($itemnum / 5);#ceil is POSIX round up function for my $i (1 .. $itemnum){ push (@tmp_row_items, $q->td($q->textfield( -name => "$champarray[$productcount][0]$i", -default => "$champarray[$productcount][$i]", -size => 25))); } push (@rows, $q->td(@tmp_row_items)); print $q->Tr(\@rows); $productcount++; }