An alternative to the recursion and readdir's and grep's is
File::Find::Rule (and you could probably do it in one statement, too, but i left it in the same general form as OP):
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
...
}
}