welcome to the world of Nematodes. larger nematodes are often visible as thin white threads between 1mm to 2 cm (0.04"- 0.8"). free living (non-parasitic) nematodes that live in the aquarium usually reside in the gravel, but when disturbed they swim in a snake like manner throughout the water column.
the scavengers are usually the most common type of nematode and while these worms themselves won't hurt your fish, they're typically found in tanks which are overfed or overcrowded.
To get rid of your worm problem, try not feeding your fish for 2 days (healthy fish will do fine with an occasional short fast, and it will improve their water quality) and giving your tank a good cleaning with a 50% water change. If you keep small fish, some of them may actually enjoy chowing down on the little worms... guppies and platies, for example, love them. If you keep your tank clean, your filter well maintained, stay true to not overstocking your tank, and do regular water changes, your worm problem should be gone in no time.
Nematodes can be introduced to the aquarium in egg or adult form. Eggs can be present in almost anything that you add to your aquarium; feeders, live plants, driftwood etc. Adult worms are more likely to be introduced by live plants and in the water accompanying your feeder fish.