replace: $output .= $template->process($file, $vars) || with: $template->process($file, $vars, \$output) || #### replace: my $output = "Content-type: text/html\n\n"; with: print "Content-type: text/html\n\n";