It sounds like camallanus worms
. Click here to see a photo of them
There are two parts to the treatment:
1) Use an antiparasitical medication such as fenbendazole, levamisole, or praziquantel.
Levamisole is supposedly the most effective treatment. (It can be hard to find though. Some people said it's available as a bird dewormer.)
2) Do FREQUENT 100% water changes.
Medications usually don't kill the parasite, they simply paralyze it. Once it's paralyzed, it can't "hold onto" the fish anymore, and gets pushed out when the fish poops. Therefore, frequent water changes are required in order to remove it from the tank.