use CGI::Ex::Template; my $cet = CGI::Ex::Template->new( UNDEFINED_GET => sub { my $self = shift; my $ident = shift; print "(".join("|",@$ident).")\n"; if (@$ident > 2) { return ''; } elsif ($ident->[0] eq 'adjective') { return 'red'; } elsif ($ident->[0] eq 'noun') { return 'fox'; } elsif ($ident->[0] eq 'verb') { return 'jumped'; } else { return ''; } }, ); my $string = "The [% adjective %] [% noun %] [% verb %] over the river.\n"; $cet->process(\$string);