title: Perl Script Help needed for duplicate filenames
body: <p>I have developed the below shell script for finding duplicate part of filename and delete it. Similiarly i need to prepare in Perl script also as perl script text processing takes lesser time.</p>
  
  <pre><code>#!/bin/bash
  for i in `ls -t *xml|awk 'BEGIN{FS="_"}{if (++dup[$1] &gt;= 2) print}'`;
  do
  rm $i
  done 
  </code></pre>
  
  <p>I have to prepare my perl script my code in such a way that only recent modified filename patterns for example </p>
  
  <pre><code>File 1: AAA_555_0000 
  File 2: AAAA_123_123 
  File 3: AAAA_452_452 [latest]
  
  File 4: BBB_555_0000 
  File 5: BBB_555_555 
  File 6: BBB_999_999 [latest]
  
  File 7: CCC_555_0000 
  File 8: CCC_000_000 
  File 9: CCC_000_111 [latest]
  </code></pre>
  
  <p>Perl Script has to pick latest file in all the filename patterns (means part of filename) in the folder and it should compare and delete the duplicates. 
  For example: script has to pick latest file in the AAA filename pattern and it has to compare with other AAA pattern if pattern found it has to delete. in the end only latest file in all filename pattern has to remain. </p>
  
  <p>Appreciate if you can help me with this logic. </p>
  
  <p>Thanks much!</p>