in reply to Regex: Example works, plugging it into code doesn't.

Inside your big foreach loop, near the beginning you do this:

while ($finalline =~ /(\w\w+[\s\.])/gc){ $linelength++; }

The /c flag prevents pos (the regex matching start position) for the string $finalline from being reset afterwards (see perlreref), so it will remain pointing to the end of the string.

Then further down, you do:

if (($finalline =~ /[A-Z][A-Z][A-Z]/) && ($caps == 0) && ($traps == 0) +){ @words = ($finalline =~ /([A-Z][A-Z][A-Z]+)/g); ... }

...but this regex will try to start matching at the end of $finalline - due to pos($finalline) still pointing there - which of course won't find any matches.

I haven't made any attempt to understand your code as a whole, so I have no idea whether you actually need the /c flag in the first regex. If you do, you can manually set pos($finalline) = 0 to reset the matching start position before the second regex.

EDIT:
Your regex /[A-Z][A-Z][A-Z]+/ can also be more succinctly written as /[A-Z]{3,}/

EDIT2:
Also, in the future please try to reduce your code to a minimal, working (except for the problem of course), self-contained testcase when asking on PerlMonks, it is really difficult to work with a to huge chunk of code that I did not write and that I cannot test (because it depends on file input, and dependencies that I don't have installed).
Also, if you follow this rule, then in many cases you will actually find the bug yourself in the process of creating this minimal testcase! :)

Replies are listed 'Best First'.
Re^2: Regex: Example works, plugging it into code doesn't.
by EclecticScion (Novice) on Jun 14, 2013 at 16:40 UTC

    That was indeed the problem. Thanks very much!