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! :)


In reply to Re: Regex: Example works, plugging it into code doesn't. by smls
in thread Regex: Example works, plugging it into code doesn't. by EclecticScion

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.