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

Hi all. Lets say I have a pattern $p and a string $s, I like to have something like that:
my @matches = ( $s =~ /($p)/ ) ;
With @mathes containing all the occurence of $p in $s . I tried almost all possible modifier and didn't managed to do it. Thx for help !

Replies are listed 'Best First'.
Re: Regexp multiple match
by thinker (Parson) on Apr 29, 2005 at 08:24 UTC

    Hi jeteve,

    What you want is the /g modifier, as this, highly contrived, example will show

    #!/usr/bin/perl use strict; use warnings FATAL => "all"; my $s = "batcatbetnetbitfit"; my $p = "b.t"; my @matches = $s =~ /$p/g; print "@matches\n"; __END__ returns bat bet bit

    cheers

    thinker

Re: Regexp multiple match
by blazar (Canon) on Apr 29, 2005 at 08:19 UTC
    /g