in reply to
Regex Pipe Return
I'm not sure what you're asking for here:
I want to keep these matches in the context of the larger string, while still being able to distinguish matches. Is there a way to substitute and return the successful event...
If "keep these matches in the context of the larger string" means "don't alter the string", then you wouldn't do a substitution; just do a match (with capturing parens), and assign the return value of the match to an array:
my @strings =
qw/XXXXXXXXXABXXXXXXX
XXXXXXXBAXXXBBXXXX
BBAABAABBXBX/;
for my $string ( @strings ) {
my @matches = ( $string =~ /([AB]{2})/g );
printf( "Found %d matches in %s: %s\n",
scalar @matches, $string, join( ', ', @matches ));
}
Perhaps you'd like to mention what you're really trying to accomplish?