for my $i (1 .. $itemnum){ push (@tmp_row_items, $q->td($q->textfield( -name => "$champarray[$productcount][0]$i", -default => "$champarray[$productcount][$i]", -size => 25))); if ($i % 5 == 0) { push (@rows, $q->td(@tmp_row_items)); @tmp_row_items = (); } }