in reply to pattern matching nested { }'s

If your text looks remotely like Perl, then Text::Balanced is worth a look. That module used to be part of the Parse::RecDescent distribution — it takes care of extracting the "Perl rules code" out of the grammars — but now it is a separate distribution.
#!/usr/bin/perl use Text::Balanced 'extract_bracketed'; $_ = <<'#END#'; This stays onValidate { stuff in here { other stuff } } This stays too #END# if(/onValidate/) { print substr($_, 0, $-[0]); # before my ($extracted, $remainder) = extract_bracketed(substr($_, $+[0]), + '{}'); print $remainder; # after print "\n## extracted: ##\n$extracted\n"; }
which produces:
This stays



This stays too

## extracted: ##
{
    stuff in here
    {
       other stuff
    }
   }