use CGI qw(:standard -nodebug); ... same code through open () ... my $table_cell = sub { print "table_cell called\n"; (@linkName) ? return td( {-align => "left"}, a( {-href => pop( @linkURL ) }, pop( @linkName ) ) ) : return td(); }; my $table_rows = sub { print "table_rows called\n"; my $rows; foreach (@linkName) { $rows .= Tr( &$table_cell, &$table_cell ); } return $rows; }; print FILE ( start_html( -title => "Favorite Links", -bgcolor => "#000000", -link => "$lcolor", -alink => "$lcolor", -vlink => "$lcolor"), table( { -align => "center" }, &$table_rows ), end_html() ) or die "write error: $!\n"; ... and close ...