But the "greedy" operator wouldn't be a problem in his case (not to say that it is a bad idea). If the greedy operator was a problem
$str = "%tag1% went to %tag2%
#with
$str = ~ s/\%(\S+)\%/$template{$1}/gi;
Would work just fine. However, the greedy operator syndrome would affect a test file such as:
$str = "%tag1%ALONGSTRINGOFTEXT%tag2%
#with
$str = ~ s/\%(\S+)\%/$template{$1}/gi;
#would yield:
#$str eq $template{"tag1%ALONGSTRINGOFTEXT%tag2"};
...because the \S+ would match all occurances of muliple-non-whitespace-then-a-percent. In this case, for that test file, it works fine, because there is whitespace demarkating the replacement targets.
(\S+?) is a really good idea, but I would also look into the problem in your
%template
--
jb