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

Greetings monks, How do I store multiple matches on a single line to an array? I trying to get two elements of "pattern" in the array.
$_ = "123patternABCpatternJJEK"; while ($_ =~ /(pattern)/gim) { push @array, $_; }

Replies are listed 'Best First'.
Re: Store multiple match single line
by moritz (Cardinal) on Sep 24, 2010 at 11:39 UTC
    Exploit the magic of list context:
    my @array = /(pattern)/gim;
    Perl 6 - links to (nearly) everything that is Perl 6.
Re: Store multiple match single line
by JavaFan (Canon) on Sep 24, 2010 at 11:37 UTC
Re: Store multiple match single line
by Utilitarian (Vicar) on Sep 24, 2010 at 11:42 UTC
    What JavaFan said
    perl -e ' $value = "12345654321"; @twos = ($value=~ /2/g);print "|", j +oin "|" , @twos,"\n";'
    Or in the example you provide,
    push @array, $1;
    take a look at perlre

    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

      You mean this, right?

      $_ = "123patternABCpatternJJEK"; while ($_ =~ /(pattern)/gim) { push @array, $1; }
        I mean that

        print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."