To get rid of and kill mealworms in your carpet you need to get some diatomaceous earth and sprinkle it all over the carpet especially where any mealworms are hanging out at.
The diatomaceous earth when sprinkled over the carpet will kill the mealworms and their larvae which is what you want to do.
I bought some diatomaceous earth at Walmart but other stores including hardware stores might carry it as well.
Allow that diatomaceous earth to sit on the carpet for an hour or even overnight and then use a vacuum cleaner to vacuum the carpet to remove both he diatomaceous earth and mealworms from the carpet.
Then go over the carpet with a carpet cleaning machine.
I rented a carpet cleaning machine to really clean my carpet much better than a home version carpet cleaning machine even though I have one.
You should also use and place mealworm pheromone traps in your pantry and cabinets where you have food to attract the adult mealworms.