in reply to Guessing source code depth with Perl.

If you want to count braces, you probably need to skip over any braces which occur inside quotes/strings, or in comments.

Code such as $sub_braces += () = $_ =~ /\{/g; itself will introduce mismatches if you don't filter them out.