The Ducks have taken two straight preseason games against their division rivals. The Ducks also beat the Sharks 5-2 in Anaheim on Wednesday.
Anaheim opened the scoring on Friday with two quick power-play goals 1:14 apart in the first period.
Perry's first power-play goal came at 4:15 as he got behind the Sharks' defense and was able to tap the puck past goalie Antti Niemi.
Jake Newton was credited with a second power-play goal at 5:29 after his shot from the blue line was deflected by San Jose's Derek Joslin into Sharks' net.
Dany Heatley got the Sharks' first goal with 16.7 seconds left in the first period when he caught Anaheim's starting goalie Curtis McElhinney kneeling off to the side of the net and tipped in the puck.
The Sharks tied the game at 2-2 at 8:29 of the second period when John McCarthy scored on a short-handed goal.
Perry added his second power-play goal to give the Ducks a 3-2 lead at 9:25.
The Sharks' Tommy Wingels scored 54 seconds into the third when he was able to take the rebound of Joe Pavelski's shot and muscle it past the Ducks' second goalie of the night Timo Pielmeier. Pavelski had three assists for the Sharks.
The Ducks retook the lead 4-3 at 4:36 of the third when Perry got his third of the game when he connected on a shot past the Sharks' second goalie of the night, Harri Sateri.
However, San Jose retied it again at 4 at 7:17 of the third when Torrey Mitchell caught Pielmeier leaning the wrong way and drilled the shot in.
Dan Sexton got the game-winner at 15:00 after the Sharks' Justin Braun lost the puck and the Ducks' Jason Blake was able to shovel it to his right wing, who shot it past Sateri.
The first period saw San Jose and Anaheim combine to run up several penalties in a fight-filled frame. The period had five fights break out in a two-minute span midway through the period. The Ducks' Shephane Veilleux and the Sharks' Scott Nichol both earned game misconducts.