http://www.perlmonks.org?node_id=246412


in reply to Constructing HTML tables with CGI.pm

It looks like you're headed towards something like the following (untested) fragment.
print $q->header('text/html'), $q->start_html('yada yada'), $q->h2('more yada'), $q->hr, $q->table( { -border => 1, -width => '100%' }, ( map { $q->Tr( $q->td($_), $q->td($host{$_}) ) } sort keys %host )), $q->end_html;
Note how map replaces the foreach you thought you'd need.

Note also that you want the header to be 'text/html'. 'text/plain' will work for some browsers (e.g., IE), but only because they try to outsmart the content type if the the body looks like HTML. Don't rely on this behavior.