use warnings; use strict; use MIME::Parser; my $parser = MIME::Parser->new(); # The message and attachment are extracted to disk, so there will be a # couple of files in this directory. $parser->output_under('/tmp'); my $entity = $parser->parse(\*DATA); if ( $entity->is_multipart ) { # This message is multipart, so look at each part for my $part ( $entity->parts ) { my $head = $part->head; # We only care about attached content in this example. if ( my $filename = $head->recommended_filename ) { print "Attachment name: $filename\n"; } } } __DATA__ Content-Type: multipart/mixed; boundary="----------=_1228756284-7253-0" Content-Transfer-Encoding: binary MIME-Version: 1.0 X-Mailer: MIME-tools 5.427 (Entity 5.427) From: me@myhost.com To: you@yourhost.com Subject: Hello, Nurse! This is a multi-part message in MIME format... ------------=_1228756284-7253-0 Content-Type: text/plain; name="short.txt" Content-Disposition: inline; filename="short.txt" Content-Transfer-Encoding: binary This is a short text file ------------=_1228756284-7253-0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: binary some literal text ------------=_1228756284-7253-0--