A serial pervert has been jailed for two years after he was caught masturbating in front of a five-year-old girl in a Kmart toy aisle — while on bail for forcing a four-year-old girl to touch his exposed genitals as she sat in a shopping trolley just metres from her mother.

Nathan Gunn, 33, already had a sex crime on his record, convicted in 2015 of indecent assault and indecent dealing of a child between 13 and 16.

He served no jail time for those crimes.

But last week, he was sent to prison for a pair of crimes that a WA District Court judge described as a “parent’s . . . worst nightmare.”

On a July afternoon last year, Gunn was drunk when he went to the Coventry Village shopping complex in Morley and approached the four-year-old girl sitting in a shopping trolley.

With her mother just 5m away looking into a freezer, Gunn brazenly approached the victim, exposed his penis and placed it into the young girl’s hands. The offence took just 30 seconds.

CCTV vision was used to identify Gunn and he was arrested, charged and bailed.

In March this year, at The Square Mirrabooka shopping centre, Gunn was again drunk, wandering the aisles of Kmart.

In the toy section, a five- year-old girl who had briefly wandered away from her mother was confronted with Gunn fondling himself, and then sniffing his hands.

He was later spotted in the food court by the victim, and when confronted by security Gunn fled through a loading bay.

But it didn’t take long for police to track him down.

This time he was kept behind bars, and last week he was sentenced by Judge Kate Glancy.

“Parents of young children inevitably have to take them to the shops ... and they just have no choice but to take their eyes off their children from time to time while they’re attending to their shopping,” Judge Glancy said.

“I suspect that you fall into the category of parents’ pretty worst nightmare.

“They’re at the shops going about their business and some drunk man comes up and decides to sexually offend against their children ... you commit what can only be regarded by right-thinking people as disgusting offences against very small, very vulnerable children.”

Gunn was imprisoned for two years. With parole and time served, he could be released by March.