my $dir="PFAD/logs/"; my $file_count=6; #... opendir ( my $dh , $dir ) or die("ERROR: Can't open $dir ($!)"); for my $sfile ( (sort {$b cmp $a}( grep {/\.od$/} readdir($dh) ))[0..$file_count-1] ){ if(open(my $fh, '<', $dir.$sfile)){ while ( my @t = split(/\|/,<$fh>,3) ){ $DATA{$t[0]} += $t[1]; } close($fh); } else { warn("WARNING: Can't open $dir$sfile ($!)"); } } close($dh);