title: how to find last index of string in perl
body: <p>I am new to perl scripting. Can some one tell me how to find the last indexof substring in a string which is repeat several times in the string.</p>
  
  <p>Actully I want to extract the file name from a give path</p>
  
  <pre><code> $outFile = "C:\\AOTITS\\BackOffice\\CSVFiles\\test.txt";
  </code></pre>
  
  <p>If I can find the last string of the '\' I cand extract the file name using <code>substr</code> function. I already did that in the following way. But it is inefficient.</p>
  
  <pre><code>$fragment =  $outFile ;
  $count = index($fragment, "\\");
  while($count &gt; -1) {
      $fragment =  substr ($fragment, index($fragment, '\\')+1);
      $count = index($fragment, '\\');
   }
  </code></pre>
  
  <p>Can some one tell me a way to do that in a efficient way.  </p>