use strict; use File::Find; my @files; # First we fill @files with the (full) path of # all files in the directory find( sub { push @files, $File::Find::name }, "/usr/home/foo/files/" ); # Now we check each file if it has become too old foreach (@files) { # If our file is older than one day, we will (try to) delete it if (-M > 1) { unlink $_; # no error checking here ... }; }; ... The rest of your script goes here ...