title: Extracting the Nth subgroup within a regex match
body: <p>Thanks so much for taking the time to read this. I'm still pretty new to Perl, so any help is appreciated!</p>
  
  <p>I am trying to use a regular expression to extract a piece of text from a large set of  large documents.  </p>
  
  <p>I have a regular expression that I use to identify where in the larger document I want to start extracting. The conditions of this regular expression are such that there often are multiple instances that match the regular expression.  I am able to identify which of these matches is the start of the body of text I want to extract.  (in the example below this would be $finds[2].</p>
  
  <p>What I would like to do is to run the same regular expression again with a .*?$END added to it to extract the text where $END identifies the end.  But what I need is a way to tell the regular expression to start extracting at the Nth occurrence of the $STAR.</p>
  
  <p>Consider this:</p>
  
  <pre><code>my $sentence = 'A1Z blah blah A2Z blah blah A3Z blah A4Z END A5Z';
  my @finds = $sentence =~ m/(A\dZ)/mg;
  
  ####################
  ##  Code that determine the element of @finds that 
  ## contains the match to the extraction I want.
  ## For this question assume it is the third match (A3Z), 
  ## Element index number 2.
  ####################
  
  $START = 2;
  </code></pre>
  
  <p>Here are my attempts: </p>
  
  <pre><code>my @finds2 = ($sentence =~ m/((A\dZ){$START}.*?(END))/mg);
  
  my @finds2 = ($sentence =~ m/((A\dZ)[$START].*?(END))/mg);
  </code></pre>
  
  <p>I would like it if the {$START} or the [$START] indicated to PERL to wait until it had the "$START"th match to start extracting and continue matching.  </p>
  
  <p>I know that my attempts aren't correct. Hopefully they help indicate what I am trying to do. </p>