The off-spinner got rid of AB de Villiers for 37 and Quinton de Kock for a duck after South Africa resumed at their overnight 98-3 at the SSC ground in Colombo. (Agencies)
At lunch, the visitors were 163-5, trailing Sri Lanka by 258 runs in the first innings. Sri Lanka made 421 in their first knock.
Jean-Paul Duminy (three) was the other batsman not-out at the crease.
The Proteas, who won the first match in Galle by 153 runs to go 1-0 up in the two-Test series, added 62 runs in the first session while losing two wickets.
South Africa started off positively and saw off the first hour without much trouble.
Amla broke the shackles with two consecutive fours off unorthodox spinner Ajantha Mendis and de Villiers followed suit, hitting paceman Suranga Lakmal for three boundaries in the same over.
De Villiers had a scare on 30 when he gloved Lakmal to the wicketkeeper but TV replays showed the ball had bounced just inches short of Niroshan Dickwella.
Amla completed his 28th Test fifty and first as captain with a single off Mendis, reaping the reward for batting with patience against the three-pronged spin attack.
But just when the partnership was building up, Perera's double-strike reduced South Africa to 150-5.
The off-spinner trapped de Villiers plumb in front of the wicket off the fourth ball, a decision the batsman sought to review but in vain. He made 37 off 99 balls and shared 79 runs with Amla.
The off-spinner got rid of AB de Villiers for 37 and Quinton de Kock for a duck after South Africa resumed at their overnight 98-3 at the SSC ground in Colombo.