steph_bow has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

I want to skip lines that begin with PA,PB or PC except PATY, but i do not know how to do this

Here is my command to skip the line.

next if (/^(PA|PB|PC).*/); # but I want to keep PATY

Replies are listed 'Best First'.
Re: lines that I do not wish to be skipped
by olus (Curate) on Mar 11, 2008 at 16:01 UTC
    while (<DATA>) { next if (/^(PA(?!TY)|PB|PC).*/); print $_; } __DATA__ PAfr PBhghg PAY fvfv PT PATE PATY hfkd dfffPATY
Re: lines that I do not wish to be skipped
by Fletch (Bishop) on Mar 11, 2008 at 15:51 UTC

    Look for "negative lookahead" in perlre, or break it into two separate conditions (if it starts with /P[ABC]/ and it doesn't start with /PATY/ then skip to the next line).

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: lines that I do not wish to be skipped
by Narveson (Chaplain) on Mar 11, 2008 at 16:12 UTC
Re: lines that I do not wish to be skipped
by halfcountplus (Hermit) on Mar 11, 2008 at 19:16 UTC
Re: lines that I do not wish to be skipped
by romandas (Pilgrim) on Mar 11, 2008 at 17:26 UTC
    Completely untested, but would this work?

    next if (/^(PA|PB|PC).*/) unless (/^PATY/);

    Edit: Sorry; this was just meant as speculation. Probably better suited for the CB; my mistake.
      It would not.

      You cannot hang two statement modifiers on the same statement.