use File::Find::Rule; my @dirs = ( $base_dir, File::Find::Rule->file()->directory()->name('*.sbd')->in( $base_dir ) ); foreach my $dir ( @dirs ){ # do your $temp_dir munging here ... my @files = File::Find::Rule->file()->maxdepth(1)->not( File::Find::Rule->name('.*', '*.html', '*.sbd', '*.msf', '*.dat') )->in( $dir ); foreach my $mail_file ( @files ){ # do your $mail_file stuff here ... } }