title: perl how to get filename and extension
body: <p>I have an input file called test1.txt with hundreds &amp; thousands of file names.</p>
  
  <pre><code>test word document.docx
  ...
  ...
  amazing c. document.docx
  1. 2. 3.45 document.docx
  ...
  ...
  </code></pre>
  
  <p>What I want to do is get filename and extension out of the string. For majority of the file names there is only one dot so I am able to get filename and ext using dot as a separator. But the problem is that some file names have multiple dots in the filenames. I have no idea how I would get the extention and file name out of that. </p>
  
  <p>Here's my perl code.</p>
  
  <pre><code>use strict;
  use warnings;
  
  print "Perl Starting ... \n\n"; 
  
  open my $input_filehandle1, , '&lt;', 'test1.txt' or die "No input Filename Found test1.txt ... \n";
  
  while (defined(my $recordLine = &lt;$input_filehandle1&gt;))
  {
      chomp($recordLine);
  
      my @fields = split(/\./, $recordLine);
      my $arrayCount = @fields;
  
  
      #if the array size is more than 2 then we encountered multiple dots
      if ($arrayCount &gt; 2)
      {
          print "I dont know how to get filename and ext ... $recordLine ... \n";
      }
      else
      {   
          print "FileName: $fields[0] ... Ext: $fields[1] ... \n";
      }
  
  }#end while-loop
  
  print "\nPerl End ... \n\n"; 
  
  1;
  </code></pre>
  
  <p>Here's the output:</p>
  
  <pre><code>Perl Starting ...
  
  FileName: test word document ... Ext: docx ...
  I dont know how to get filename and ext ... amazing c. document.docx ...
  I dont know how to get filename and ext ... 1. 2. 3.45 document.docx ...
  
  Perl End ...
  </code></pre>
  
  <p>What I would like to get</p>
  
  <pre><code>FileName: test word document ... Ext: docx ...
  FileName: amazing c. document ... Ext: docx ...
  FileName: 1. 2. 3.45 document ... Ext: docx ...
  </code></pre>