title: Recovering a specific line in multiple .txt in a directory using Perl
body: <p>I have the results of a program which gives me the results from some search giving me 2000+ file txt archives. I just need a specific line in each file, this is what I have been trying with Perl:</p>
  <pre><code>opendir(DIR, $dirname) or die &quot;Could not open $dirname\n&quot;;
  
  while ($filename = readdir(DIR)) {
   print &quot;$filename\n&quot;;
   open ($filename, '&lt;', $filename)or die(&quot;Could not open  file.&quot;);
    my $line;
    while( &lt;$filename&gt; ) {
      if( $. == $27 ) { 
      print &quot;$line\n&quot;;
      last;
      }
   }
  }
  closedir(DIR);
  </code></pre>
  <p>But there is a problem with the $filename in line 5 and I don't know an alternative to it so I don't have to manually name each file.</p>