use CGI qw/:standard *table *Tr/; ... # decide rows and columns of table ... # e.g. AoA @rows where each element points to an array of cells ... # perhaps each cell could point to a hash of the image data print $query->start_table(...); for my $row (@rows) { print $query->start_Tr(...); for my $cell (@{$row}) { print $query->td(...); # insert image data here } print $query->end_Tr(); } print $query->end_table(); ...