use strict; use warnings; use Date::Parse; my @AoA_files=(); open IN, $ARGV[0]; while() { my $infile=$_; chomp $infile; if($infile=~/^(\d+)\_(\d+)_(\d+)_(\d+)_(\d+)_(\d+)_(\d+)_(.*)/) { my $uid=$1; my $year=$2; my $month=$3; my $day=$4; my $hour=$5; my $minute=$6; my $second=$7; my $actual_filename=$8; my $timestamp = "$year-$month-$day"."T"."$hour:$minute:$second"; if ( grep { $_->[1] eq $actual_filename } @AoA_files ) #if filename exists, keep only the most recent one { #compare the timestamps my $existing_timestamp = $_->[0]; my $difference_in_seconds = str2time($timestamp) - str2time($existing_timestamp); if($difference_in_seconds > 0) #current date is newer than the one in the AoA - use this one { push @AoA_files, [ $timestamp, $actual_filename]; } } else #add it normally to the AoA { push @AoA_files, [ $timestamp, $actual_filename]; } } }