sub parse { use MIME::Parser; my $dir = "c:\\tmp\\parsedemails"; if (not -d $dir) { mkdir $dir or die "Can't create directory $dir: $!\n"; } ### Create a new parser object: my $parser = new MIME::Parser; ### Tell it where to put things: $parser->output_under($dir); ### Open the file: open my $fh, '<', $fileopen or die "Can't read $filopen: $!\n"; ### Parse an input filehandle: my $entity = $parser->parse($fh); # $entity->dump_skeleton; $path = "c:\\tmp\\parsedemails"; opendir(DIR, $path); @lines = readdir(DIR); closedir(DIR); ### the last directory name, is the name of the newly most recently created directory by Mail::Parser $directory = $lines[$#lines]; Print "DIR $directory END "; $pathdir = $path."\\".$directory; opendir(DIR, $pathdir) or die "can't opendir $pathdir: $!"; while (defined($file = readdir(DIR))) { push @files, $file; # Print " FILE $file END"."\n"; } closedir(DIR); } # end sub