SAN FRANCISCO -- The Chicago Cubs refuse to count themselves out of the NL wild-card chase until they are mathematically forced to call it a year.
A successful road trip brought the swagger back to this bunch.
"My hope doesn't need reinvigorating," manager Dusty Baker said. "I had hope regardless."
Neifi Perez hit a tiebreaking RBI double in the eighth inning against his former team, and the Cubs wrapped up an impressive stretch away from Wrigley Field with a 3-2 victory over the San Francisco Giants on Sunday.
Jerry Hairston hit a two-out double against LaTroy Hawkins (2-6) -- traded by the Cubs in May -- before Perez lined a double to left for the go-ahead run.
Matt Murton homered and Todd Walker had an RBI triple in the second for the Cubs, who finished their road trip at 8-2 and pulled within 5½ games of the wild card-leading Houston Astros.
"Stranger things have happened," said Cubs closer Ryan Dempster, who worked the ninth to convert his 13th straight save opportunity and his 27th in 29 chances overall. "We've got to keep playing hard. I think absolutely we put too much pressure on ourselves (earlier). We'd be four games back and try to make up three games in one."
Moises Alou tied the game at 2 in the sixth when he scored on a wild pitch by Michael Wuertz, but Alou pulled his left groin on the play and left the game shortly after. He is expected to miss Monday's game. Wuertz (5-2) recovered for the win.
Alou had two hits and drove in a run for the Giants, who lost for the fifth time in six games. Without Alou, his manager, father Felipe, must make contingency plans for Monday's lineup. Moises was to move from left field to right and from the cleanup spot to fifth in the order for Barry Bonds' long-awaited season debut after recovering from three surgeries on his right knee since Jan. 31.
"It's been hard to get Mo and Barry in the same lineup all year," Felipe Alou said.
Brett Tomko pitched seven strong innings in his second start since returning from his second demotion to the bullpen, but failed to earn his first win since beating Florida on July 22. The right-hander has since gone 0-5 in seven starts.
He wore a new number for this occasion, switching from No. 50 to the 35 he sported in college. Tomko was the Giants' best pitcher down the stretch last season but never got into a groove this year, leading the Giants to move him into a relief role.
"I thought I pitched pretty well, but I've had the same results all year," Tomko said. "Maybe there's a little luck in my future. We didn't capitalize. We've let opportunities slip away and we're running out of games."
Murton made it 2-1 when he hit a solo homer to left on the first pitch he saw from Tomko in the fifth -- the rookie's first home run against a right-hander. Tomko got eight straight outs before the homer, then retired his final eight afterward.
Randy Winn led off San Francisco's half of the first inning with a double, then scored on Alou's single to left.
A cheerful Bonds looked upbeat and relaxed as he prepared to come off the 60-day disabled list and play for the first time this year.
The slugger will be in the starting lineup when the Giants open a three-game series against the NL West-leading San Diego Padres on Monday.
Bonds took batting practice and shagged fly balls in the outfield Sunday. He joked around with Cubs star Nomar Garciaparra and former teammate Jerome Williams, traded to Chicago earlier this season.
He even shook hands with a baby.
"Right now, I'm just trying to keep my mind clear, that's it," Bonds said while quietly gripping his bats in his black recliner in the corner of the clubhouse.
Bonds has been eager for months to resume his quest of Hank Aaron's home run record. He received medical clearance to play Saturday from Dr. Lewis Yocum, the Angels' team orthopedist who worked with Bonds for more than two months in Los Angeles.
"We need a lift and Barry brings expectations when he comes to the plate," Felipe Alou said. "It will energize the crowd and the team."
The Giants are already receiving last-minute credential requests from national media outlets sending reporters to cover Bonds' return. ... Released Giants' LHP Kirk Rueter came in to clean out his locker and pick up his car and pack up his home. He is attending the dedication of a Little League field on Tuesday. "It's not too bad," he said of being at the ballpark. "It's different because I'm not playing." ... Winn had his 16th multihit game since joining the Giants in a July 30 trade with the Seattle Mariners. ... Omar Vizquel's ninth-inning throwing error snapped a 19-game errorless streak for the nine-time Gold Glove SS.