In the second season of the show there was an episode called Summer Belongs to You where Dr. Doofenshmirtz works with Perry the Platypus to rescue his daughter Vanessa Doofenshmirtz. In the third season there was an episode called Agent Doof where Dr. Doofenshmirtz tries to become a secret agent working for the good guys and accidentally causes more problems than he did when he was evil so he decides to go back to being evil. In the Season Three episode, Where’s Perry, Dr. Doofenshmirtz builds a machine called the “Ultimate Evil-Inator” to turn Perry’s wikt:boss Major Monogram evil but accidentally hits Monogram’s assistant Carl making him turn evil. So Doof ends up working with Monogram and Perry to stop Carl because Carl is a more dangerous villain than Doof was so Dr. Doofenshmirtz builds a machine called the Re-Good Inator and turns Carl good again. In the movie Phineas and Ferb: Across the Second Dimension, Dr. Doofenshmirtz goes to a parallel universe where a more evil version of himself already won and Doof ends up stopping the other him from taking over the Tri-State Area from the main universe. In the Season 4, episode Mission Marvel, Doofenshmirtz accidentally steals the powers of the superheroes from Marvel Comics and teams up with the Marvel supervillains but the villains betray him so Doofenshmirtz helps stop them. In the Season 4 episode Minor Monogram, Doofenshmirtz’s sidekick betrays Dr. Doofenshmirtz and tries to take over the world so Doof helps stop him. In the Season Four episode, “Primal Perry” Dr. Doofenshmirtz hires a hunter from Australia named Liam to trap Perry the Platypus but ends up working with Perry to stop him after Liam tries to kill them both. In the episode Doof 101, it’s revealed that after summer ended Dr. Doofenshmirtz was given a choice between jail and community service and ended up as a high school science teacher. And the episode Act Your Age set in the future reveals that Dr. Doofenshmirtz didn’t commit any crimes since then. In the episode Phineas and Ferb save Summer, Dr. Doofenshmirtz helps the good guys stop a mad scientist named Rodney from putting the world in a new ice age but says he’s still evil. In the horror episode Night of the Living Pharmacists, he accidentally starts a zombie pharmacist apocalypse and helps to stop it. In the series finale Last Day of Summer, he builds a machine called the Do-Over Inator so that he can start the same day over any number of times and accidentally nearly destroys the universe so he tries to save it from himself and his daughter Vanessa convinces him to turn good.