From:
Fish Disease and Treatment Diseases
Nematoda
Symptoms: Worms hanging from the anus.
Nematodes (threadworms) infect just about anywhere in the body but only shows itself when they hang out of the anus. A heavy infestation causes hollow bellies. Lighter infestations usually cause no problems with the fish.
Short of destroying the fish, which is easier, two treatments have been suggested. First treatment; soak the food in parachlorometaxylenol and give the fish a bath or treat the aquarium with 10 ml per liter. The bath should last for several days. Second treatment; find special food containing thiabendazole as a nematode (threadworm) cure and hope the fish will eat it.