Real manager Zinedine Zidane made three changes from the side that thrashed Huesca, with Raphael Varane, Ferland Mendy and Toni Koos recalled while Inter were still without striker Romelu Lukaku due to injury.
The Nerazzurri came very close to going ahead in the tenth minute after Nicolo Barella headed Perisic cross from around the penalty spot into the crossbar.
The visitors gifted Los Blancos the lead in the 25th minute after Karim Benzema intercepted a pass from Achraf Hakimi and rounded goalkeeper Samir Handanovic before slotting into an empty net.
Sergio Ramos gave Madrid a two-goal lead in in the 33rd minute with a flicked header at the near post after a pin-point corner by Kroos.
Antonio Conte's troops pulled a goal back two minutes later after Martinez met Barella's cross and found the bottom corner with his sweeping effort.
Inter got the equaliser in the 68th minute when it was least expected, as Perisic skipped past a challenge in the box before guiding a half-volley over goalkeeper Thibaut Courtois.
Martinez had a wonderful chance to put the visitors ahead in the last quarter of an hour after Mendy headed a clearance straight into his path but after carving out space for a shot on the edge of the box, he curled strike narrowly wide.
Second-half substitutes Rodrygo and Vinicius Junior combined brilliantly for Madrid's winner in the last ten minutes, as the latter and fired an unstoppable strike into the top corner.
Los Blancos held on in the end to clinch their first win of the campaign that lifted them up to third in the group, just a point behind leaders Borussia Monchengladbach, while Inter were left two points behind at the bottom.