my $entity = $parser->parse( IO::File->new( "$dir/raw-message.$i") ); foreach my $part ($entity->parts()) { # Look at $part (a MIME::Entity object) and determine what to do with it }