Assuming you've followed along and managed to get a valid $entity (isa MIME::Entity), the following example from the manpage of the same name is pretty nifty:
# Only keep text parts
my @keep = grep { $_->effective_type =~ m|^text/| } $entity->parts;
$entity->parts(\@keep);