You don't. They're supposed to sit on your face until you rage quit out of annoyance
Jk. Since you put stall in the tags, I'm going to assume that this is single battles and Pex is bad in vgc, according to Wolfey anyway
First off, there's always the ever not so reliable Heatran. Tran is a pain for non shed shell pex. Heatran just traps it with magma miss, taunts it and earth powers it to death. It also completely scorches Ferrothorn, if magma miss hits anyway. Be warned though, that by using Heatran, you will be crippled by losing your leftovers or something and you will be annoyed by leech seed from Ferrothorn while Pex can leave you at low hp due to scald
A favorite of mine and the one I use to deal with these two is Tapu Fini. That might seem weird because both Pex and Ferro resists Fini's stabs but it's actually the opposite. With a set of whirlpool, taunt, nm and either scald or moon blast, Fini effectively lures in both of them, traps them, and kills them. Nature's madness is the key because it cuts fifty percent of the opponent's current hp, effectively bypassing the type resistance. If you play this on gen seven though, be careful against Ferrothron because our hated durian carries power whip for Greninja. In gen eight, Ferro doesn't carry power whip that much as far as I've noticed anyway but agian, you will most likely lose your leftovers
If you wanna be like the soviets in stalingrad and wanna brute force your way thru them, Garchomp does just that. It does have to watch out for scald burns but with a simple set of fire fang, scale shot / stealth rock, earthquake and swords dance, you brute force your way thru them. This is made more effective if you have Fini as its teammates because now you make sure that Pex can't status you at all and Pex's ice beam, which it almost enver runs, is too weak against Garchomp
If you play this on gen seven, then you have a lot of options to play with. Medicham destroys this core, Greninja can hax it with dark pulse flinch, Mawile can run coverage for both of them, Mega Zam has psychic and focus miss for both, z psychic Volcarona incinerates this core while the above three are still around and are still as effective at killing them
On gen eight, the first three I mentioned just straight up destroys both of these mons. There are also new options such as bulk up cc Zeraora or if you can get it in against a mon that doesn't threaten it, Blacephalon can force both into a hell of a situation. Hydreigon also annoys both and has reliable recovery and the rare mix Dracozolt on sand
Finally, you can also overwhelm them both by rain boosted water moves from the likes of Keldeo, Rapid Urshifu, Greninja and even the Barracuda. If you don't want brute force, taunt is your best option. It completely shuts down both of them because they will be forced to attack. Tornadus, along with the already mentioned Heatran and Fini does this very well and can force them to switch out, sometimes anyway
There is also a dishonorable mention that deals with these two easily. Magnezone and this applies in both gen seven and eight. Zone traps Ferrothorn and burns it with hp fire or body presses it to death in gen eight. It also has a super effective thunderbolt to delete Pex from the battle and doesn't particularly mind a burn
Perhaps most importantly, anticipate when these two are coming in and take advantage of that. That is the most reliable way to deal with not just these two but to put your opponent into an uncomfortable spot