in reply to Can't quite get this regex working

By default a . in a regex doesn't match \n so your "contents" match doesn't get what you expect. Add a s flag to the regex to give /\Q[[$tag_name]]\E(.*?)\[/s and some of what you want will work better. If you add strictures (use strict; use warnings;) you'll find out that there is more work to do however.

True laziness is hard work