Perry stroked in breaks of 79 and 104 to lead, before going 4-2 ahead after nicking the sixth frame on the final black.

China’s Ding won the next frame by a point, but Perry clinched the two he needed including a century to advance.

Perry will face Northern Irishman Joe Allen, who beat John Higgins in the last 16, in the quarter finals on Friday, 1pm start.

It was Perry’s first win at the Masters at his seventh attempt.

He said: “I’m so pleased to win. I wouldn’t say it’s a monkey off my back because it’s so hard to win here.

“But I’m so pleased because when people ask me the best I’ve done in the Masters I always have to say I’ve never won a match. Now at least I can say quarter-finals.

“I’ve always been one of the bottom eight seeds in the tournament so I’ve got to pull off a shock to win. But I’ve managed to do that now.”