The visitors, replying to Sri Lanka's first innings total of 494, were all out for 312 on the third day, trailing the hosts by a massive 182 runs.
Herath took the final wicket just two balls into the last session before rain stopped play, finishing on 3-72. Off-break bowler Perera chipped in with 3-53.
Mendis' unbeaten 166 lifts Sri Lanka to commanding position against Bangladesh
Bangladesh skipper Mushfiqur Rahim made a dogged half-century and shared 106 runs for the seventh wicket with Mehedi Hasan, ensuring the visitors avoided the follow-on.
Herath bowled his Bangladesh counterpart Mushfiqur on the stroke of the tea break for 85 after the latter took their score past the 300 mark.
Perera broke Mushfiqur's stubborn partnership with Mehedi when he trapped the young all-rounder plumb leg-before for 41 runs.
Bangladesh recall Mustafizur for Sri Lanka Tests
The 34-year-old off-spinner took the wicket of Taskin Ahmed off the next ball with a successful review after his appeal for lbw was turned down by umpire Marais Erasmus.
Mushfiqur and Mehedi's efforts came after Bangladesh lost four wickets in the opening session that had threatened to derail their innings completely.
Fast bowler Suranga Lakmal took the key wicket of opening batsman Soumya Sarkar for 71 after Bangladesh resumed the day on 133 for two.
Bangladesh lost their first wicket when overnight batsman Sarkar top-edged Lakmal's rising delivery to Lahiru Kumara at fine leg.
Soumya added just five runs to his overnight 66, his 137-ball knock containing eight fours and a six.
Shakib Al Hasan contributed 23 rapid runs off 19 balls before flicking a sliding delivery from Sandakan down the leg side where wicketkeeper Niroshan Dickwella completed the catch.
Mahmudullah (8) and wicketkeeper-batsman Liton Das (5) also threw their wickets away with loose shots.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ