Sounds like planaria. Very common in the aquarium and harmless to your fish, but unsightly. Like herpmommy said they are usually a symptom of overfeeding.
This is what planaria look like greatly magnified:
Check your water parameters, it's likely that your nitrates are too high. That is potentially very bad for your fish and you need to address the root problem at once.
First of all you need to clean your substrate to get rid of the worm's food source. You need to do it thoroughly to get all the uneaten food. Suck some of the worms up as you're cleaning. This may take a couple of days to get it all. Watch your water parameters while doing this. If you do this, and maintain a regular regimen of tank maintenance, they will eventually disappear.
There are other methods you can employ that are faster, but each of them have their owns problems associated with them as well.
1) You can raise the heat of the aquarium, but it would have to be at like 95F for several hours to affect them. It would kill most of them, but will be hard on your fish. You can temporarily remove them if you want to do this.
2) Salt can be used, but there are many species of planaria that are salt tolerant and it would have no effect on them. Planaria area lso found in saltwater too.
3) You can use a chemical solution. From checking around I've found that there are some products you can use to rid yourself of them. Those products would be albendazole. Vermex, CopperSafe, FlukeTabs.
I even heard of one guy using dog dewormer to get rid of them. He used 10% of the pack for every 10-gal and said it worked. Never tried it myself.
The problem with some of these chemical solutions is that many of them contain copper. Copper will kill any invertebrates that you have in the tank. That means snails, shrimp, crabs, crayfish, etc.
4) Get some guppies, from what I understand they are one of the few fish that will eat planaria.
You can try any of these ideas, but I think your best solution to this problem is what I said at first. Clean your substrate and keep it clean. Watch your water parameters and keep them under control. If you do those 2 things, you should never see planaria in your tank again.