Purple worms will eat shriekers on sight; the reason given for this is that purple worms enjoy eating shriekers.  1/13 of the monsters a shrieker summons with its shriek are purple worms; this can rarely cause a purple worm to appear very early in the dungeon.
Purple worms tend to be dangerous if you are unprepared. This is because the purple worm can engulf you, and as soon that happens it will start to digest you ("The purple worm digests you!"). If you are not able to kill the purple worm fast, it will kill you. To ensure survival after being engulfed, immediately zap a wand of digging. The purple worm will have its health points dropped to 1, so one hit will get rid of it. See also engulfing. If you are wielding a cockatrice or chickatrice corpse, stoning the purple worm while inside will give the message: "You jump through an opening in the new statue of a purple worm."
Wearing a ring of slow digestion will prevent a purple worm from killing you via engulfing."You get regurgitated! Obviously the purple worm doesn't like your taste."
Ranged attacks are of course also an option.
Be careful when leaving pets around purple worms, as they will run up to the worm and promptly be engulfed. Pets that are engulfed die instantly. This is a good way to lose a very powerful pet. This does not apply to pets that are being ridden. However, if a purple worm engulfs you while you are riding, it will force you to dismount and your pet will be vulnerable. For the same reason, purple worms make powerful pets, as they can instantly kill things by engulfing them. Unfortunately, they are extremely vulnerable to shapeshifters because engulfing them alive or eating their corpse will polymorph the worm.
Pet worms can level quickly as well as reach levels beyond their normal maximum by engulfing wraiths.
Polymorphing yourself into a purple worm allows you to dispatch even elusive and powerful enemies, such as the dreaded arch-lich, in a single turn by engulfing and digesting them--so long as you are not wearing a ring of slow digestion. The lack of limbs, however, impedes prolonged progress in this state, and you must take special care not to swallow deadly prey such as a cockatrice. Note that when you engulf a wraith, you only get the normal XP for the kill, and do not gain a level like a pet does.
A gargantuan version of the harmless rain-worm, the purple
worm poses a huge threat to the ordinary adventurer. It is
known to swallow whole and digest its victims within only a
few minutes. These worms are always on guard, sensitive
to the most minute vibrations in the earth, but may also
be awakened by a remote shriek.