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

hi monks

I have a little confusion in the below code's behaviour. I found that the builtin variable $& is not having the reliable value in it. Initially I tried to print the values available in $` and $'. but I found a misleading answer when I print $&.
I picked this code from a very large program. I beleive that monks can definitely clear my doubts.

$_ = foo; /foo/; # prints "bar\n" for (qw/bar baz/) { print "$&\n" unless /bar/; } # prints "foo\n" for (qw/bar baz/) { next if /bar/; print "$&\n"; }

"Keep pouring your ideas"