Matt Cain pitched five perfect innings for the San Francisco Giants on Monday, but the Chicago Cubs rallied for a 3-2 victory.

The right-hander, who will be the Giants' No. 2 starter behind left-hander Madison Bumgarner during the regular season, threw 59 pitches and struck out seven.

Right-hander Jeff Samardzija, the Cubs' opening-day starter, also had an effective outing. He gave up two runs in four innings and struck out five.

Pablo Sandoval's two-run single in the fourth gave the Giants an early lead, but the Cubs scored a run in the sixth and two in the seventh. The decisive run scored on two infield errors as part of the same play.