Switching out removes the effect of Perish Song from the Pokémon, which will prevent it from fainting. You could even switch it out on the first turn of Perish Song, and then bring it back in on the second or third turn and it won’t faint.
If your Pokémon uses Perish Song, and the opponent KOs it before they faint from it, it will still KO them on the 3rd turn if they don’t switch.