altough you may find that these worms are harmless to your fish, i'd just like to inform you that a friend of mine had this same incident and told me that they did not harm the fish but instead they starting ruining and harming his fish tank. These worms were starting to eat the silicon between the glasses attached together, he was in a very bad situation because if he did not repair it in time then the tank would be unbalanced and cause a tank crack. He had to buy a clay made for aquariums and had to empty the tank until where the silicon had been eating. Lukily his fish and tank was fine and now he goes through the correct procedures to remove all the existing and future worms in his tank (i am unaware of how to remove them).
But because of Pegasus' handy and helpful website you can go through this procedure:
"To get rid of your worm problem, try not feeding your fish for 3 days (no, this is not cruel... 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 25% 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. "
good luck