To answer a few more questions:
  1. while ((my $line = <INFILE>) && ($line !~ /SEQ.../)) (Removed as per tye's second comment. Just look below - it's better code anyways.)
  2. It's Perl, not PERL
  3. The regex match operator is =~. The regex not-match operator is !~. It's an atomic 2-character-long operator, not something like += or -=.
  4. Rewrite as such:
    while (my $line = <INFILE>) { # Do a match against the line, grabbing the number. my ($num) = $line =~ /SEQRES\s{2,5}(\d)\s/; # This means that the line didn't meet our requirements # as defined by the regex. So, go get the next line. # (I added this ... you may not want it, depending on # what else you're doing in the loop.) next unless defined $num; # If that number is 2, leave the while loop. last if $num == 2; # Don't chomp unless there's a possibility we'll use it. chomp $line; # If the number is 1, print it to two places. if ($num == 1) { print "$line\n"; print OUTFILE "$line\n"; } }
Make it obvious what the difference is between the two matches. I assigned the difference to $num, which was done via the capture mechanism of regexes. (Look for the parentheses.)

Update: Changed code per tye's comments.

------
We are the carpenters and bricklayers of the Information Age.

The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.


In reply to Re: more than one condition to a while loop by dragonchild
in thread more than one condition to a while loop by anchorite

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.