in reply to Re: conditional regex
in thread conditional regex

If the expected input is y or yes in a line then following code can be used simply.

while(<>) { print "yes\n" if /(^y$|^yes$)/i; }

Replies are listed 'Best First'.
Re^3: conditional regex
by ikegami (Patriarch) on Aug 23, 2010 at 17:01 UTC
    So could
    while(<>) { print "yes\n" if /^y$/i || /^yes$/i; }
    while(<>) { print "yes\n" if /^y$/i; print "yes\n" if /^yes$/i; }

    By the way, useless capturing greatly slows down pattern matching.