in reply to Regex returns match the first time. It returns everything thereafter

    if ($line =~ /line/../\\Z/) { ... }

The  /line/ regex is bound to (i.e., matches against) the  $line scalar. The  /\\Z/ regex is not explicitly bound to any scalar, and so matches against the  $_ default scalar, which is not initialized to anything in the code shown in the OP. So no, the  /\\Z/ regex never matches and the  .. flip-flop operator never flops back to its false state. Doesn't this match against an undefined value produce a warning? Are you using warnings?

Replies are listed 'Best First'.
Re^2: Regex returns match the first time. It returns everything thereafter
by guitarplayer68 (Novice) on Nov 18, 2013 at 13:28 UTC

    Yes I am using warnings and there are no undefined value messages.

      This could be explained if  $_ had been assigned a defined value by some operation previous to the code shown in the OP.

      The other twist I noticed is that the regex is really  /\Z/ and not  /\\Z/. The former regex matches everything, even undef (although a warning is still generated for a match against undef if warnings are enabled).