use vars qw/$template/; $template = undef; #calls foo foo() #outputs page print $template->output; sub foo { $template = HTML::Template->new(filename => 'test.tmpl'); # fill in some parameters in the template $template->param(home => $ENV{HOME}); $template->param(path => $ENV{PATH}); }