Pakistan, seeking a series-levelling win, paid for sloppy fielding as Sri Lanka recovered from a middle-order collapse to make 337 in their first innings on the third day at Pallekele.
The tourists, trailing by 111 runs, were 27-1 in their second knock by stumps, losing opener Taufeeq Umar for four, leg-before to seamer Nuwan Kulasekara.
Mohammad Hafeez was unbeaten on eight and Azhar Ali was on six, with Pakistan trailing by 84 runs with nine wickets in hand.
“We have quite a fight ahead of us,” said Pakistan coach Dav Whatmore. “The wicket is still playing well, but we have to bat long and deep to save this game.”
No series win since 2009
Sri Lanka, aiming for their first series win since 2009, won the first Test in Galle by 209 runs before the second in Colombo was drawn.
Sri Lanka were only 10 runs ahead when they lost their seventh wicket, but Perera and Kulasekara (33) snatched the initiative by adding 84 for the eighth.
Perera, a 23-year-old from Colombo playing only his sixth Test, smashed four boundaries and three sixes in his maiden half-century after being dropped twice on 11 and 22.
Perera, whose four wickets in the first innings engineered Pakistan’s collapse for 226, was last man out when he was bowled by left-arm seamer Junaid Khan.
Junaid finished with 5-70, his second successive five-wicket haul, while off-spinner Saeed Ajmal claimed 3-66.
Tharanga Paranavitana and Thilan Samaraweera led Sri Lanka’s charge with a fourth-wicket stand of 143 after surviving a testing morning session in overcast conditions.
Photos: Akshay Kumars son Aarav's night out in Juhu
Photos: Shilpa Shetty, son Viaan, Geeta Basra on 'Aunty Boli Lagao Boli' sets
Photos: Isha Ambani and mom Nita show their stylish side
Photos: Ileana D'Cruz flaunts plunging neckline in black dress
Photos: Shamita Shetty, Bhumi Pednekar at fashion show