# The variable $entity contains a MIME::Entity object returned from MIME::Parser # and from this object, a MIME::Body object is retrieved for content manipulation. my $body = $entity->body; my $content = $body->as_string; # The content of the MIME component can now be modified as you see fit $content =~ s/foo/bar/g; # The updated content must now be written back into the MIME message component - # This is performed through manipulation of the MIME::Body object. my $io = $body->open('w'); $io->print( $content ) $io->close; # At this point, you may need to re-synchronise the headers of the MIME::Entity # object - This method will add or update a Content-Length header within the # MIME component. $entity->sync_headers( 'Length' => 'COMPUTE', 'Nonstandard' => 'ERASE' );