Responding to Pakistan's 226 all out, the hosts survived Junaid Khan's five-wicket haul to reach 337, having earlier slipped from 187 for three to 220 for six at lunch.
Perera, whose four wickets were so crucial in removing the Pakistan top order on the opening morning, hit an impressive 75 off just 86 balls - including four fours and three sixes - to ensure his side a decent first-innings advantage. Tharanga Paranavitana (75) and Thilan Samaraweera (73) also passed fifty for Sri Lanka in a 143-run fourth-wicket stand, before both fell to Saeed Ajmal.
Sri Lanka were finally all out late in the day, but there was still time for six overs of Pakistan's second innings, with Taufeeq Umar's dismissal for four - lbw to Nuwan Kulasekara - a significant loss as the tourists closed on 27 for one, still trailing by 84 runs.
Sri Lanka, already 1-0 up in the series heading into the final Test, began the day on a rather shaky 44 for three. And with day two washed out by rain, Pakistan would have been hoping to make further inroads early on to boost their chances of claiming victory in Pallekele and salvaging a draw from the series.
But they met stiff resistance from Paranavitana and Samaraweera on Tuesday morning and afternoon.
The pair kept the score ticking along at around three an over and rarely looked troubled before Ajmal made the breakthrough, trapping Samaraweera plumb in front after the right-hander played down the wrong line.
Angelo Mathews had made just nine before he cut a wide Khan delivery to Asad Shafiq in the gully while Paranavitana departed after chopping Ajmal on to his stumps to end his stoic 188-ball stay and leave Sri Lanka reeling.
Prasanna Jayawardene managed just 20 before he was trapped lbw by Umar Gul as Sri Lanka slipped to 236 for seven, but that was the cue for Perera and Kulasekara to hit back with a timely 84-run eighth-wicket stand.
Khan finally broke the partnership when he removed Kulasekara for 33, while Rangana Herath added just two runs before his dismissal, lbw to Ajmal, left Sri Lanka on the brink. Perera's was the last wicket to fall as Junaid (five for 70) set the seal on an impressive personal display.