in reply to how to match after the n-th occurance?
In your case, that'd be:($nth_chunk) = $text =~ /(?:PREFACE(MATCH)POSTFIX){N}/;
The reason it works is because a capturing group INSIDE a quantifier keeps on overwriting the associated $DIGIT variable on each repetition. Here's a simpler example:my ($number13) = $text =~ /(?:<TD nowrap>(.*?)</TD>\n){13}/;
"abcdef" =~ /(.)/; # $1 is "a" "abcdef" =~ /(.)+/; # $1 is "f"
|
|---|