A 23-year-old man who struck a Mercedes-owner in the head with a machete in a bid to steal the vehicle has been sentenced to three years in prison.

The District Court of Western Australia was told Lawrence John Cashin attempted to carjack the 24-year-old victim while he sat with his girlfriend parked on a street in the northern Perth suburb of Girrawheen on May 13 last year.

During the attack, Cashin threatened to kill the male victim and struck him with a machete on the top of his head and near his ear.

Throughout the ordeal, the victim's girlfriend was cowering on the floor of the car.

"The victim was screaming, the girlfriend wouldn't get out of the car, and ultimately you ran off," Judge Gillian Braddock said during the sentencing.

"Not only did the victim suffer the deep lacerations to the top of the head and the ear, to need to go to hospital and be treated there, it must have been a totally terrifying experience for them."

Judge Braddock said Cashin was at high risk of violent reoffending, given he had a traumatic early life and addictions.

He was beginning to realise the need to address his problems and was attempting to parent his girlfriend's daughter, so there was hope for reform but it wouldn't be easy, Judge Braddock said.