#!/usr/bin/env perl use warnings; use strict; use Data::Dump qw/dd pp/; use Template::Parser; my $text = <<'END'; before [% # this is a comment to the end of line foo = 'bar' %]

bw, bliako

[%# placing the '#' immediately inside the directive tag comments out the entire directive %] [% outside %] after END my $parser = Template::Parser->new(); my $tokens = $parser->split_text($text); #dd $tokens; # Debug my $o = ''; for (my $i=0; $i<@$tokens; $i++) { if (ref $tokens->[$i]) { my $text = $tokens->[$i][0]; #dd $text; # Debug $o .= "[% $text %]"; } elsif ($tokens->[$i] eq 'TEXT') { my $text = $tokens->[++$i]; #dd $text; # Debug $o .= $text; } else { die pp($i,$tokens->[$i]) } } print $o; __END__ before [% # this is a comment to the end of line foo = 'bar' %]

bw, bliako

[% outside %] after