title: How do I find the index location of a substring matched with a regex in Perl?
body: <p>I am iterating through a file and on each line I am looking for a regex. If the regex is found I just want to print "it's found" and then the index location of where it was found in that line. </p>
  
  <p>Example: </p>
  
  <pre><code>looking for: 'HDWFLSFKD' need index between two Ds
  line: MLTSHQKKF*HDWFLSFKD*SNNYNSKQNHSIKDIFNRFNHYIYNDLGIRTIA
  output: 'its found' index location: 10-17
  </code></pre>
  
  <p>The above 'looking for' is quite simple but I am planning to have complex regex statements in there.<br>
  So basically Just want to know if a regex is found in a string then how do we get the index location of it?</p>
  
  <p>Here is the code I have so far:</p>
  
  <pre><code>foreach my $line (@file_data)
  {
          if ($line=~ /HDWFLSFKD/){
              print "it's found\n"; 
              print "but at what index are the two Ds";
            }   
          else {
              $sequence.=$line;
              print "came in else\n";
          }
  }
  </code></pre>