in reply to conditional regex

What you have will match anything that contains "y" or "Y" (e.g. "xyz") because you didn't specify where the characters must occur.
print "yes\n" if /^y(?:es)?$/i;

Replies are listed 'Best First'.
Re^2: conditional regex
by gobisankar (Acolyte) on Aug 23, 2010 at 06:02 UTC

    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; }
      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.