Sumanth Sharma wrote: > > Hi, Hello,
> Read with Patience. > > Backreferences( $1, $2 ...) are lexically scoped, > > which means > > in a match like m/(<REGEX1>)(<REGEX2>) etc ..../ > > Suppose REGEX1 does not match, then $1 remains undefined, and if REGEX2, > 3 ... do match then $2, $3 will respectively hold the matches in parentheses > 2, 3 etc. > > My problem is > say $some_var = "ababababababab"; ##here ab occurs 7 times > > if I say > > @get_match_list = ( $some_var =~ m/(ab){5,14}/g ); > ## i.e get a least 5 matches and at most 14 > > @get_match_list will contain only one val i.e "ab", > that's b'coz $1 is lexically scoped to the first( the only ) parentheses > in the reg-exp. > > So, $1 is overwritten on each match. > > IN SUCH A SCENARIO, IS IT POSSIBLE TO GET ALL THE MATCHES It has nothing to do with $1 because you are not using $1 in the expression. The problem is that the capturing parentheses are only capturing the pattern 'ab'. You need to use non-capturing parentheses to return the complete match: @get_match_list = $some_var =~ /(?:ab){5,14}/g; Or put capturing parentheses around the complete pattern: @get_match_list = $some_var =~ /((?:ab){5,14})/g; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>