in reply to problem with endless loop

$tr looks like it is a global variable. Once it is bigger than $cols you will enter the main loop, skip the TR loop, not increment $cols and do the same..endlessly.

strict.pm would have caught this typo. Also you are less likely to get into endless loops, off by one, and so in if you use the Perlish foreach style of looping:

while ($count < $elements) { # Do you use $tr? If not, then don't bother declaring it... foreach my $tr (1..$cols) { $test .= "<tr>"; foreach my $tc (1..$rows) { $count++; # Do stuff } } }