Resuming after lunch on 347-5, the tourists made use of the easy-paced wicket to build a challenging total, with veteran Younis Khan top-scoring with 177.
Khan, who came in to bat at 19-2 on the first morning and ended the day on 133, anchored the innings with the help of lower-order batsmen.
The 36-year-old, who is playing his 90th Test, batted for eight hours and 16 minutes, hitting 15 boundaries and a six in his 24th Test century.
Pakistan's wicket-keeper Sarfraz Ahmed made 55 and shared a sixth-wicket stand of 66 with Khan when he lobbed an easy catch to mid-on to give Perera his second wicket.
Also Read
The off-spinner had Saeed Ajmal and Junaid Khan caught at leg-slip by Mahela Jayawardene, taking the retiring former Sri Lankan captain's tally to 202 Test catches.
Only India's Rahul Dravid has taken more catches (210) by a fielder other than a wicket-keeper.
Pakistan, who resumed at their overnight score of 261-4, went to lunch on 347-5 with Asad Shafiq making 75 during a fifth-wicket stand of 137 with Khan.
The visitors added 32 runs in the first hour when left-arm spinner Rangana Herath broke through for Sri Lanka by trapping Shafiq leg-before. The batsman's appeal to the TV umpire went in vain.
Sri Lanka came close to removing Khan when he was on 156, but seamer Shaminda Eranga spilled a sharp return catch as the batsman failed to keep a drive along the ground.