best way to do it, cause i've had them almost that bad, is to vacuum as many as possbile cause when they die they release a ton of toxin into the water and can nuke your tank.
use airline tube and siphon them out into a filter bag until you don't see to many left, i did this for a week or two.
than dose with flatworm exit and if possible have a carbon reactor full of carbon ready to go cause after about 1 hour after treating you need to start running carbon and skimmer.