Australia, who were set a mammoth target of 413, were 133 for seven at lunch on the third day with Peter Nevill and Mitchell Starc battling to survive Sri Lanka's spin test.
Overnight batsmen David Warner and skipper Steven Smith offered some resistance with their 51-run fourth wicket partnership but both of them fell to Perera's guile.
Warner, who tried to counter attack during his 31-ball 41, was trapped lbw off a straighter Perera delivery that hit the batsman on the front pad.
Perera, who also took two wickets on Friday, then bowled Adam Voges for 28 to register his fourth five-wicket haul in 11 Test matches.
More From This Section
But it was veteran spinner Rangana Herath who set up Sri Lanka's chances of victory after bagging his maiden Test hat-trick to help dismiss Australia for a record low of 106 in their first innings.
Herath and Perera shared four wickets between them on a chaotic second day which saw the fall of 21 wickets and put the match on the fast track.