#! /usr/bin/perl -w use strict; my $directory = shift || '.'; opendir D, $directory or die "Cannot open directory $directory: $!\n"; my %age; while( defined( my $file = readdir D )) { next if $file eq '.' or $file eq '..'; my $canonical = "$directory/$file"; $age{$canonical} = (stat $canonical)[9]; } closedir D; my $count = 0; foreach my $file ( sort {$age{$b} <=> $age{$a}} keys %age ) { next if ++$count < 10; print "$file (@{[scalar localtime $age{$file}]})\n"; # or unlink $file if you are feeling brave }