use HTML::Template; my $file = '/path/to/example.tmpl'; my $template = HTML::Template->new( filename => $file ); # do all the work to create the content my $content = "Start of Content"; # ... # pass content to the template $template->param( CONTENT => $content ); print "Content-Type: text/html\n\n"; print $template->output;