The Red Devils had lost to Brighton last weekend
First innings centurion Dimuth Karunaratne then made a fluent 60 as the hosts ended day two on 111 for four, leading by 272 runs at the Galle International Stadium.
Angelo Mathews, on 14, and Roshen Silva, on 10, were batting at close of play after left-arm spinner Keshav Maharaj claimed three wickets for South Africa.
But it was the Sri Lankan bowlers who starred on a dramatic day that witnessed South Africa slip to 51-6 before being bowled out for 126 in the second session of play.
The dismal effort set a new low for South Africa in Sri Lanka, worse than their 169 in Colombo in 2006.
Perera returned impressive figures of 4-46 with his off-spin, while paceman and stand-in skipper Suranga Lakmal took three wickets.
Veteran spinner Rangana Herath started Sri Lanka's dominance by sending back nightwatchman Maharaj early, and Perera soon took crucial wickets including the dangerous Hashim Amla for 15.
Skipper Faf du Plessis made a gritty 49 and his 64-run seventh-wicket partnership with Vernon Philander, who made 18, was the best that South Africa could muster in their 54.3 overs.
Herath grabbed two wickets while left-arm wrist spinner Lakshan Sandakan claimed one - the three spinners sharing seven wickets in total.
Lakmal did not bowl at all until the 37th over of the innings, but was effective after lunch on day two, rattling the off-stump of du Plessis with a delivery that jagged in sharply.
Lakmal then quickly got rid of the number nine and 10 batsmen to end the innings with figures of 3-21 from only 4.3 overs.
Having established a lead of 161, Sri Lanka quickly set about extending it when they began their second innings, with the openers putting on a 51-run partnership.
Karunaratne became only the second Sri Lanka batsman to score a hundred and a fifty in the same Test against South Africa, but was caught at slip off the bowling of Kagiso Rabada late in the day.
Sri Lanka 1st innings 287
South Africa 1st innings (overnight 4-1)
D. Elgar c Mathews b Perera 8
A. Markram c Mathews b Herath 0
K. Maharaj lbw b Herath 3
H. Amla c Mendis b Perera 15
T. Bavuma b Sandakan 17
F. du Plessis b Lakmal 49
Q. de Kock b Perera 3
V. Philander lbw b Perera 18
K. Rabada b Lakmal 2
D. Steyn c Mathews b Lakmal 8
T. Shamsi not out 0
Extras: (b2, nb1) 3
Total: (all out, 54.3 overs) 126
Fall: 1-1, 2-9, 3-13, 4-40, 5-48, 6-51, 7-115, 8-115, 9-123, 10-126.
Bowling: Herath 19-5-39-2, Perera 23-8-46-4, Sandakan 8-1-18-1, Lakmal 4.3-0-21-3 (nb1)
Sri Lanka 2nd innings
D. Gunathilaka c Rabada b Maharaj 17
D. Karunaratne c Amla b Rabada 60
D. de Silva b Maharaj 9
K. Mendis lbw b Maharaj 0
A. Mathews not out 14
R. Silva not out 10
Extras: (lb1) 1
Total: (4 wickets, 37 overs) 111
Fall: 1-51, 2-64, 3-64, 4-92.
Bowling: Rabada 7-0-28-1, Steyn 5-1-15-0, Maharaj 16-4-37-3, Shamsi 6-0-20-0, Philander 3-0-10-0
Toss: Sri Lanka
The Red Devils had lost to Brighton last weekend
The Asia Cup, which was originally to be held in Sri Lanka, will be played from August 27 to September 11
As soaring temperatures across England forced the need for water breaks at all this weekend's Premier League games, it was City who were on fire at the Etihad as promoted Bournemouth were blown away
Goals from Danny Ings and Emi Buendia eased the pressure on Gerrard after a run of two wins in their previous 12 games dating back to last season
Spurs lost four times to Chelsea last season, including three defeats, two in the League Cup semifinal followed by one in the league, in January
French international striker Karim Benzema is the overwhelming favourite after being the architect of Real Madrid’s 14th Champions League title
The Aspire control and command centre will monitor all stadiums at once, as Qatar pulls out all the technical stops to keep an eye on the anticipated one million plus visitors from the moment they get off the plane to moment they leave
Kieron Pollard, Dwayne Bravo, Nicholas Pooran and Trent Boult are set to join ahead of the inaugural edition