#!/usr/bin/perl use strict; my $older_than = 45; # my @dirs = #could be this depending then just foreach them my @files = ; foreach my $filename (@files) { next unless (-d $filename); # this is only letting dirs get past if ( int( -M $filename) > $older_than) { #do something print"dir is old:$filename\n";#print what is deleted here. # test what you are going to delete #&erase_directory ($filename); # after test uncomment this #rmdir $filename; # after test uncommnet this } } sub erase_directory { my $directory = shift @_; my @files = <$directory/*>; foreach (@files){ unlink "$_"; } }