in reply to array of strings that matched a pattern
use warnings; use strict; use Data::Dumper; my $s = 'a b c d'; my @letters; if (@letters = $s =~ /(\w)/g) { print Dumper(\@letters); } __END__ $VAR1 = [ 'a', 'b', 'c', 'd' ];
See perlre and Perl Idioms Explained - @ary = $str =~ m/(stuff)/g
Can you show an example of your input string and your regex?
Update: If you use perl 5.10, you could use named captures and the %- hash.
use warnings; use strict; use Data::Dumper; if ('1234' =~ /(?<A>1)(?<B>2)(?<A>3)(?<B>4)/) { print Dumper(\%-); } __END__ $VAR1 = { 'A' => [ '1', '3' ], 'B' => [ '2', '4' ] };
|
|---|