A worm is a worm is a worm. Or maybe not. In fact there are many different types of worms and sometimes the only thing they have in common is that vermiform shape. This is particularly true of platyhelminthes (flatworms), nematodes (round worms) and annelids (segmented worms).
Let's begin with the most primitive group, the flatworms. Flatworms are flat because they do not have a body cavity and therefore the three cell layers are not separated. They have a two way gut with food entering the mouth and waste products leaving the same way because the gut dead ends and there is no anus. Nematodes and annelids have a body cavity and are round instead of flat. They also have one way guts with a mouth at one end and an anus at the other.
Nematodes differ considerably from annelids, however, and that is why they are in separate phyla. Nematodes are not segmented and their body cavity or coelom forms in a completely different way to the annelid coelom. Nematodes have what is called a pseudocoelom that is lined on one side with mesoderm and on the other side with endoderm. Annelids on the other hand have a true coelom, which is formed entirely within the mesoderm.
Both the pseudocoelom and the coelom give advantages to the nematodes and annelids that platyhelminths, with no body cavity, do not have. Because the muscles (mesodermal tissue) are joined to the gut (endoderm) in platyhelminthes, they cannot move their muscles separately to their gut. In nematodes, annelids and all higher animals, the movements of the gut (peristalsis) are quite separate from the movements of muscles that propel the body across or through the substrate. This is an important evolutionary advance, made quite separately in the nematodes with their pseudocoelom and the annelids with their ' true' coelom.
Annelids have made some other advances that take them beyond the simple body plan of the average nematode. One important difference is segmentation. Annelids have a head, followed by body segments and a tail. Each segment has its own muscles, nerves and excretory organs, and each segment is like the car of a train, both independent and yet part of the whole.
This is the beginnings of specialisation, where different body segments can have different functions. For instance, the insects, which evolved from annelids, have specialised the first three segments behind the head to be the thorax, which has the wings and limbs and contains the heart and circulatory system. The segments in annelids have not led to such a level of specialisation, but there is more specialisation than in either the platyhelminths or the nematodes. The segmented body plan allows for efficiency, with each segment able to carry out basic life processes. It also suits animals that are basically burrowers. The segmented body plan of earthworms, for instance, makes it possible for them to move quickly and efficiently through the soil.
There are some basic muscular differences between the three types of worms as well. The first one that we have already discussed is the separation of muscles from guts in the nematodes and annelids. A close look at the way nematodes and annelids move shows the other muscular difference: nematodes only have longitudinal muscles, which is why they seem to thrash back and forth, without the smooth forward motion possible in annelids, which have both longitudinal and circular muscles. Annelids also have setae or little hairs on each segment that help them move. Neither flatworms nor roundworms have these.
So these three phyla are as different as they are similar. They can all be called worms because of their similar body plans but beneath these superficial similarities lie fundamental differences that have led to taxonomists putting them in separate phyla.