Try making your quantifier, in this case +, non-greedy, with a ? after it. Look it up on
perlre, search for 'greedy'.
Updated:Look up
Common Regex Gotchas in our
Tutorials secion.
Update 2: As
loc and
JayBonci mention, it is most likely not your regex, although I would still look into not making it greedy, but your hash might have a problem. Also there are quite a few templating systems out there, for HTML, etc... might be worth looking into, since you might run into lots of exceptions, and regexes, as powerful as they are, might not handle it (cleanly).
Update 3: Again, helped by
someone else, /i modifier might provide the wrong key, since hash keys, since they *are* case sensitive.