use strict; use warnings; use Template; use Template::Stash; my $template_string = <<'END_OF_TEMPLATE'; [% x1 = "x1_defined_in_template" -%] Inside the processed template: x1 = [% x1 %] x2 = [% x2 %] x3 = [% x3 %] END_OF_TEMPLATE my $stash = Template::Stash->new(); my $tmpl = Template->new( STASH => $stash ); $stash->set( x1 => 'x1_defined_in_stash_set' ); $stash->set( x2 => 'x2_defined_in_stash_set' ); $stash->set( x3 => 'x3_defined_in_stash_set' ); my $t_vars = { x3 => 'x3_defined_in_process_t_vars' }; # Process and print the template $tmpl->process( \$template_string, $t_vars ) or die $tmpl->error(); print "Post-process, the stash vars are:\n"; print ' x1: ', $stash->get('x1'), "\n"; print ' x2: ', $stash->get('x2'), "\n"; print ' x3: ', $stash->get('x3'), "\n"; print "Note that we could check more easily via _dump:\n"; print $stash->_dump(), "\n";