opendir my $d, $dir; my @f = sort { -M $b <=> -M $a } map { "$dir/$_" } grep !/^\.{1,2}$/,readdir $d; unlink @f[-0,1] if @f > 20;