I have a program which looks through a protein sequence (just a string of letters) to see if it has N's in it. The results look roughly like this:

BC001593 91 NPSL
BC001593 262 NASS
BC001593 293 NAST

I just need to match the numbers (91, 262, 293...) as these are the positions of the N's. I've tried this:

if ($string =~/\w{1,12}\s+(\d{1,5})\s+[a-zA-Z]{4}/sm){ $sites = $1; }

and it matches the first number 91, fine, but no more. I tried s and m modifiers but no luck. How can I search through every line and record the value of every match? In addition, there can be any number of such letters present, so I need to search until there are no more lines left. Any ideas?


In reply to matching every occurrence of a regex by Becky

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.