in reply to Re: Match typo
in thread Match typo

How to check in a line words "publish" and "date" exists or not. I have to print the "matched" if publish and date both exists in line
while(<DATA>){ $ =~ m/publish|date/; } __DATA__ The book was published on the date "20-08-2009".

Replies are listed 'Best First'.
Re^3: Match typo
by almut (Canon) on Sep 11, 2009 at 08:40 UTC

    If you want an exact match, that's easy:

    while (<DATA>){ print "matched\n" if /publish/ and /date/; }

    But note that this would also match "the date was published on"...

    If the order in which the words must occur is relevant, you could do

    while (<DATA>){ print "matched\n" if /publish.*date/; }
    A reply falls below the community's threshold of quality. You may see it by logging in.