title: How can I get a list of all files with a certain extension from a specific directory?
body: <p>I'm using this code to get a list of all the files in a specific directory:</p>
  
  <pre><code>opendir DIR, $dir or die "cannot open dir $dir: $!";
  my @files= readdir DIR;
  closedir DIR;
  </code></pre>
  
  <p>How can I modify this code or append something to it so that it only looks for text files and only loads the array with the prefix of the filename?</p>
  
  <p>Example directory contents:</p>
  
  <pre><code>.
  ..
  923847.txt
  98398523.txt
  198.txt
  deisi.jpg
  oisoifs.gif
  lksdjl.exe
  </code></pre>
  
  <p>Example array contents:</p>
  
  <pre><code>files[0]=923847 
  files[1]=98398523
  files[2]=198
  </code></pre>