title: Recursive open files in Perl
body: <p>I have a Perl script to count how many times an expression appered in a file, in this particular case it counts everything found between '&lt;' and '>' because i wanted it to parse .xml files.</p>
  
  <p><strong>SCRIPT:</strong>     </p>
  
  <pre><code>#usr/bin/perl
  
  sub by_count {
     $count{$b} &lt;=&gt; $count{$a};
  }
  
  open(INPUT, "&lt;[Content_Types].xml");
  open(OUTPUT, "&gt;output");
  $bucket = qw/./;
  
  
  while(&lt;INPUT&gt;){
     @words = split(/\&lt;/);
  
     foreach $word (@words){
              if($word=~/($bucket*&gt;)/io){
  
        #print OUTPUT "$word";
        #print OUTPUT "\n\n";
        $count{$1}++;}
  
     }
  }
  foreach $word (sort by_count keys %count) {
  
     print OUTPUT "&lt;$word occurs $count{$word} times\n\n";
  
  }
  
  close INPUT;
  close OUTPUT;
  </code></pre>
  
  <p><strong>OUTPUT</strong></p>
  
  <pre><code>&lt;Default Extension="xlsx" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"/&gt; occurs 1 times
  
  &lt;Default Extension="png" ContentType="image/png"/&gt; occurs 1 times
  
  &lt;Override PartName="/word/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/&gt; occurs 1 times
  </code></pre>
  
  <p><strong>PROBLEM</strong></p>
  
  <p>I want to do it recursively. I have a directory with multiple subdirectories inside, and inside each subfolder there is a [Content_Types].xml file. Any suggestion on how to parse every file with that name found in the main directory?</p>
  
  <p><strong>Example diagram:</strong></p>
  
  <pre><code>&gt;Directory
    &gt;Directory1
      &gt;[Content_Types].xml
    &gt;Directory2
      &gt;[Content_Types].xml
    &gt;Directory3
      &gt;[Content_Types].xml
    .
    .
    .
  
    &gt;Directory100
      &gt;[Content_Types].xml
  </code></pre>