Theyre detritus worms and they are harmless. Now matter how clean you keep a tank they will always be living in the substrate.
Detritus Worms (from the group of worms called Oligochaetes, sub group naidid worms) are often misidentified in the aquarium hobby as Planaria without close inspection by many internet articles such as about.com.
Many of these worms are accidentally introduced by live plants, gravel (especially in the case of common Detritus Worms) live fish foods, and even brought in with fish transfers.
Many not familiar with Detritus worms will label these as everything form midge larvae, Planaria to baby earthworms, of which none is true. They are very common and most often seen during vacuuming and other cleaning procedures.
These worms generally are not a problem, however high numbers of particular species can indicate low oxygen levels and low filter productivity, which very often suggests some degree of pollution caused by poor cleaning procedures, over crowding, over feeding and poor filtration
Please reference these sources for even more identification (and further information so as to dispel the internet aquarium myth that these are Planaria):