A long worm, w~~~~ , is a monster that occupies several squares. Only its head can attack, but if it is hit in the middle (even with bare hands), it may divide into two. Attacking the tip of its tail cannot cause it to split, making it a good way to kill long worms. Unlike purple worms, long worms cannot engulf their enemies.
Pet long worms and their baby forms cannot be displaced, which is annoying if you want to improve it with a polytrap. The DevTeam intended the whole length of a long worm to be dangerous, but currently software limitations prevent this.
A long worm technically respects Elbereth and other means of scaring. However, if a worm is frightened but is currently stuck, it will proceed to attack you with its head and all of its tail segments next to you. This is the only way to see this in action, presumably due to a bug.
The long worm is one of the oldest monsters in NetHack history, having been around since Jay Fenlason's Hack. It is unknown if its behavior was different than it is in modern NetHack.
The long worm represents the sandworm, or rather a small and thus a very young sandworm, from Frank Herbert's Dune series of novels. This is suggested by the fact that long worms are excessively large (for NetHack), by the encyclopedia entry, and by the fact they drop a worm tooth, which may be made into a crysknife, as in the novels. In the Dune series, "specimens [have been] observed over 400 meters" in length. (Presumably the shorter length of long worms in the Mazes of Menace is an adaptation to a more constrained environment.)
In the novels, sandworms can be ridden; however, NetHack's long worms cannot.
The worms of Dune also contribute to the creation of the highly useful and desirable Spice, a fact which is homaged in UnNetHack and xNetHack: if you eat a long worm corpse, the taste is described as "spicy".
[The crysknife] is manufactured in two forms from teeth taken
from dead sandworms. The two forms are "fixed" and "unfixed".
An unfixed knife requires proximity to a human body's
electrical field to prevent disintegration. Fixed knives
are treated for storage. All are about 20 centimeters long.
This page is based on a spoiler by J. Ali Harlow.