Here is some pseudocode to work from:
push header from row into hash element
@{$hash{HEADER}}
push content from row into hash element
@{$hash{CONTENT}}
to print table then you can just do something like the following (untested):
print "<TABLE><TR><TD>",
join "</TD><TD>",@{$hash{HEADER}};
print "</TD></TR><TR><TD>,
join "</TD><TD>",@{$hash{CONTENT}};
print "</TD></TR></TABLE>";
-enlil