#!/usr/bin/perl -p BEGIN{print '#>#g ; } ]]>'; my $open='$open!g; } # if must be on one line! # {{# if }} for (my $count=3; $count>0 ; $count--) { s!{{\#([^}]*)}}(.*?){{/\1}}!$close$open$2$close$open!g; s!{{\^([^}]*)}}(.*?){{/\1}}!$close$open$2$close$open!g; } # {{{...}}} s#{{{([^\#\^\/][^}]*)}}}#$close$open#g; # {{...}} s#{{([^\#\^\/][^}]*)}}#$close$open#g; # {{/ iteration }} if (m!{{\/([^}]*)}}\s*$!) { chop($pref); s!{{\/([^}]*)}}!$close$open!g; } END{print $close."\n";}