Perera (95) and Mathews made life difficult for Pakistan through their 112-run seventh wicket stand before Sri Lanka declared their first innings at 428-9, leaving Pakistan to score 19-0 in a tricky six overs before the close of the second day's play.
Openers Ahmed Shehzad (five) and Khurram Manzoor (14) survived an anxious time as Pakistan go in search of a big lead to square the series after losing the second Test by nine wickets in Dubai.
Sri Lanka, leading the series 1-0 after the first Test ended in a draw in Abu Dhabi, are aiming to seal the series.
The day once again exposed the flat Sharjah stadium pitch as Mathews put 73 for the sixth wicket with Prasanna Jayawardene (35) and then batted solidly with Perera, leaving Pakistani bowlers frustrated and failing in their search for quick wickets.
The 31-year-old Perera, who made his one-day debut in 2007 but had never played a Test before, looked more solid during his 305-minute batting as he drove and pulled with perfection before