The Spaniard's quick-fire first-half brace, which came minutes after the Saints' James Ward-Prowse had escaped a red card for a cynical challenge on Miguel Almiron, looked to have put the Magpies in complete control.
However, Southampton boss Ralph Hasenhuttl made a double change at the break and one of the newcomers, Mario Lemina, pulled one back before Perez settled it four minutes from time with his 11th goal of the season.
Rafael Benitez's men, who have won six of their last seven home games in the league to go 10 points clear of Cardiff, were decidedly ordinary for much of the second half, but ultimately emerged with a huge victory as the bulk of the crowd at St James' Park pleaded with the manager to sign a new contract.
In a hectic opening to the game, it took a fine block by Matt Ritchie to deny Ward-Prowse after Nathan Redmond had picked him out with a 22nd-minute pull-back.
But last man Ward-Prowse was fortunate to stay on the pitch seconds later when he blocked Almiron on halfway as he attempted to race clear with support. Referee Anthony Taylor produced only a yellow card to the fury of Benitez and his players.
The Magpies' anger was soothed within four minutes when Perez received the ball inside the box and patiently awaited his moment before dispatching his shot past the helpless Angus Gunn.
Perez had to wait just four minutes to double his tally when Salomon Rondon's selfless run down the left gave him the opportunity to cross to the far post, where the Spaniard arrived on cue to beat the keeper from close range.
Almiron, still awaiting his first goal for the Magpies, scuffed a shot 41st-minute straight at Gunn after Rondon had forced Maya Yoshida into an error, although Paul Dummett had to make a telling intervention on the stroke of half-time to repel Josh Sims' goal-bound effort.
Hasenhuttl made his move at half-time when he sent on Lemina and Stuart Armstrong for Jack Stephens and Sims, and the visitors might have been back in it within three minutes when Yoshida glanced a header wide from Ward-Prowse's corner.
However, Ki Sung-yueng was unfortunate not to extend Newcastle's lead when his skidding 55th-minute strike evaded Gunn's dive, but came back off the foot of a post.
The Saints were enjoying their best spell, with Lemina giving them a foothold in midfield, and it was he who reduced the deficit four minutes later with an accomplished right-foot finish.
The Magpies wobbled as Southampton sensed an opportunity and Yoshida headed over from Redmond's 66th-minute cross when he might have done better.
Isaac Hayden would have calmed the nerves with a stinging 70th-minute volley but for a stunning save from Gunn, but Perez finally did so when he flicked Ritchie's header home to claim the first Premier League hat-trick for the club since Georginio Wijnaldum scored four against Norwich in October 2015.