After bundling out Sri Lanka for 292, the Proteas moved to 63-2 at lunch in their second innings for an overall lead of 226 runs with eight wickets in hand.
The visitors had made 455-9 declared in their first innings.
New Test skipper Hashim Amla was batting on seven with Faf du Plessis on eight at the break.
South Africa started off cautiously against a bowling attack that relied heavily on spin in the absence of frontline seamer Shaminda Eranga, who is injured.
More From This Section
He faced 29 balls and hit two fours in his 12-run knock.
Alviro Petersen (32) took on the spinners fearlessly, twice reverse-sweeping Perera in the same over for boundaries to step up the scoring.
In the end it was Perera who brought Petersen's promising innings to an end with a good length ball that he nicked to Chandimal.
Earlier, South Africa wrapped up the Sri Lankan innings in the fifth over of the day with paceman Morne Morkel (3-49) sending back overnight batsman Herath for 19.
Sri Lanka added just nine runs to their overnight score of 283-9.
Pace spearhead Dale Steyn was the star of the South African bowling, finishing with 5-54, his 23rd five-wicket haul in Tests.
The visitors were dealt a blow when paceman Vernon Philander was fined 75 percent of his match fee Friday after being accused of ball-tampering.
Philander, who bowled 15 wicketless overs for 31 runs, did not bowl on Saturday.