first of all, sorry that this happened to you. Sometimes it seems like all the big talk about women's rights is just candy floss. The advisors so far have assumed that you are in the USA. I would say restraining order is the way to go if you are in USA. But if not, you'll have to seek a solution within the law of land, wherever you are based.
What is more shameful is the HR tried to coerce you too.
Well, i am a bit aggressive in these matters and my advise will probably work in any country, any situation, against anyone. Although it is not a very 'decent' way. First of all, take a deep breath and have no fear. This is 2024 and it is not a woman's fault if she is stalked or coerced. Unless you take the fight to the enemy's camp, the enemy will enjoy doing whatever he has been doing.
step 1 : take the fight to his camp. Counter attack. May be call him, recorder on, ask him what he has been upto, tell him that you will reach out to his wife before reaching out to attorney.
step 2 : if step 1 is too bold, have some male buddy to 'softly' harass him. Blank calls, or just random calls in the night abusing him for no reason, send love letters by post to his apartment, or a bouquet of red roses with romantic greeting cards.... you see.. get his wife to nag him. He harassed you. You harass him ten times over.
step 3 : have a male buddy make a fake woman's account. You are in tech so I don't need to tell you how. There is AI, paid followers, fake photos etc etc etc. Let a beautiful woman reach out to him, make friends with him, have long phone calls with him during office hours, record everything. Then send anonymous packet to QC HR saying that Mr. Casanova is romancing during office hours on office money. Send the recordings also to his wife. After you have given him a solid counter punch, call him using the same fake account, apologize for sending the recording to HR etc, arrange a meeting at a cafe. When he does come over, sp-t on his face in front of everyone and leave.
Look, call it my background in the services, but I believe if he has harassed you for five years, you should stop at nothing less than destroying his career + family life. That plus law and he will be cured forever.