in reply to Re: Re-use of a global match
in thread Re-use of a global match

That statement needs to be qualified. It is far from always true. The /g modifier is part of Perl for a reason and there are many things one can do with it that are much more difficult without it.
$foo = (join ', ', 'abacadaeafagahaiaj' =~ m/a/g ); print $foo . "\n";

Replies are listed 'Best First'.
Re^3: Re-use of a global match
by mrpeabody (Friar) on Aug 02, 2007 at 05:00 UTC
    /g can be useful. But if you just want to know if something matches (which for me is most of the time), you don't need it.

    The cases where m///g is useful are where:

    • you need to save the position of the last match, or
    • you're counting or saving the matches for later use (assigning the result of m/// to a variable)

    In practice, I find myself using /g only in substitutions.