#!/usr/bin/perl -w use strict; use File::Find; my $max_age_days = 120; find({ wanted => sub { unlink if -f $_ and -M _ > $max_age_days }, postprocess => sub { rmdir $File::Find::dir }, }, @ARGV);