#!/usr/bin/env perl use strict; use warnings; use CGI; use Template; use FindBin qw($Bin); use constant TEMPLATE_PATH => "$Bin/"; (my $template = __FILE__) =~ s/\.pl$/.tt/; # Derive the template from the script name. my $data = {list => [qw(foo bar baz)]}; render($template, $data); sub render { my ($temp, $data) = @_; my $t = Template->new({INCLUDE_PATH => TEMPLATE_PATH}) || die "$Template::ERROR\n"; $t->process($temp, $data) || die $t->error, "\n"; }