#!/usr/bin/perl # vim: set ts=4 sw=4 et sta: use strict; use warnings; use File::Spec; my $dir = '/var/mail'; my $max_age = 30; sub read_dir { my $dir = shift; # no input, no result return () if !defined $dir; opendir my $dh, $dir or die "$dir: $!\n"; # read entries from directory, exclude . and .. # create path for and to each entry and store # results in @entries my @entries = map { File::Spec->join( $dir, $_ ) } grep { ! m{\A\.\.?\z} } readdir $dh; closedir $dh; return @entries; } ### MAIN my @to_check = read_dir( $dir ); for my $entry ( @to_check ) { if ( -M $entry > $max_age ) { print "$entry is older than $max_age.\n"; } }