Martinez (2-0) gave up four hits and walked two in the longest of his three starts this season. Jordan Walden pitched eighth and Trevor Rosenthal finished for his seventh save in seven tries, completing a five-hitter.
Heyward belted a solo shot off Matt Garza in the third, lifting St. Louis to a 2-0 lead. Peralta homered leading off the sixth.
Garza (1-3) allowed seven hits in six innings while striking out a season-high six.
Milwaukee has dropped nine of 10. At 3-14, the Brewers have the worst record in the majors.
The Brewers threatened in the third, but were hurt by poor baserunning.
Garza led off with his fourth career walk and advanced to second on Jean Segura's single. As Gerardo Parra squared to bunt, Garza broke for third. Initially ruled safe, Garza was called out after a review. Parra then struck out and Segura was caught stealing.
Yadier Molina's run-scoring groundout got St. Louis on the board in the second, but the All-Star catcher left in the fifth in what the team said was a precautionary move. Molina appeared to be in pain after a foul tip struck him in the knee guard in the fourth. He is day to day.
Cardinals: OF Peter Bourjos returned after being on paternity leave for three days. His wife, Ashley, gave birth to a son, Maxton. Infielder Dean Anna was optioned to Triple-A Memphis to clear a roster spot for Bourjos.
Brewers: OF Carlos Gomez continues to make progress in recovering from a right hamstring injury. He is on the 15-day disabled list. ''He's hitting again out on the field. He ran on the treadmill,'' manager Ron Roenicke said. ''Hopefully, it'll be those 15 days or just a couple added onto that.''
Cardinals: Adam Wainwright (2-1, 1.71 ERA) took the loss against the Brewers in St. Louis' home opener on April 13. He is 12-8 with a 2.37 ERA in 31 career games versus the Brewers.
Brewers: Wily Peralta (0-2, 5.68 ERA) will make his second start of the season against St. Louis. He is 4-5 with a 4.58 ERA in 10 career starts against the Cardinals, but went 3-1 with a 2.18 ERA in five starts against them last season.
Link to box score: St. Louis (11-4) 3 at Milwaukee (3-14) 0