While on screen he was making millions laugh on TV's biggest show, Matthew Perry was locked in a painful cycle of addiction, and a battle with demons that stemmed from a damaged childhood.
In 1986, after moving to Los Angeles, Matthew Perry was convinced fame would wash all his problems away.
"I yearned for it more than any other person on the face of the planet," he wrote in his candid memoir last year.
"I needed it. It was the only thing that would fix me. I was certain of it."
Perry would eventually get his wish, becoming one of the six central stars of the most beloved sitcom of the past 30 years.
Stardom as the sharp-witted Chandler Bing on Friends also brought fortune - in the form of $1.1m an episode - and a string of glamorous girlfriends.
Yet behind the scenes, Perry's struggles to keep his personal life and health on the rails only seemed to grow.
In his autobiography, Perry traced his insecurities - as well as his comic talents - back to a childhood that was split between his divorced parents, but in which he felt a sense of abandonment from both.
His mother was a Canadian beauty queen-turned-journalist who served as press secretary to Prime Minister Pierre Trudeau. His father was a US actor who starred in adverts for Old Spice aftershave.
Most of Perry's upbringing was in Ottawa, Canada, but he said he was a "latchkey kid" because his mother's job "just meant I spent a great deal of time alone".
"Accordingly I learned to be funny - pratfalls, quick one liners, you know the drill - because I had to be," he said.
His mother had a stressful job, "and me being funny tended to calm her down enough so that she would cook some food, sit down at the dinner table with me and hear me out - after I heard her out of course".
As for his dad, "I saw his face more often on TV or in magazines than I did in reality". But he was "my hero", he wrote.
By the age of 10, Perry started misbehaving - stealing money, smoking, letting his grades nosedive, and at one point beating up his schoolmate and Trudeau's son Justin - now Canada's PM.
He first drank at 13, and deep down, he said he was determined to shut everyone out from his feelings of abandonment.
When he moved to LA to live with his father at 15, he seemed to be heading for a tennis career, having been a ranked youth player in Canada.
But he found competition tougher in California and set his sights on acting instead. He got parts in 1980s sitcoms Charles in Charge and Growing Pains, then lead roles in 1990's Sydney and 1993's Home Free.
When a script for another new sitcom called Friends Like Us came along, Perry immediately saw himself in it.
"When I read the script for Friends Like Us, it was as if someone had followed me around for a year, stealing my jokes, copying my mannerisms, photocopying my world-weary yet witty view of life," he said.
"One character in particular stood out to me. It wasn't that I thought I could play Chandler. I was Chandler."
One small catch was that he had already committed to appearing in a "sci-fi comedy" about baggage handlers at Los Angeles airport in the year 2194.
But that turned out to be terrible and fell through - as did the actor who was the first choice to play Chandler in the other show, now titled just Friends.
So Perry became the last, and youngest, lead actor to be cast.
He was immediately sure it would be a success. When he first met creator Marta Kauffman, "I knew right then and there just how huge it was all going to be".
He was right. The show became a hit and the fame he craved had arrived. But it didn't wash his problems away.
Aniston confronted him
Making the shows could be painful, he said. "I felt like I was going to die if the live audience didn't laugh, and it's not healthy for sure, but I could sometimes say a line and they wouldn't laugh, and I would sweat and just go into convulsions.
"If I didn't get the laugh I was supposed to get, I would freak out. I felt that every single night. This pressure left me in a bad place."
He began drinking more in the hope that vodka would fix the things that fame hadn't.
At one point, it was so bad that Jennifer Aniston confronted him. He wrote: "'We can smell it,' she said, in a kind of weird but loving way, and the plural 'we' hit me like a sledgehammer."
But Perry said his co-stars rallied round to support him, and he got a sober companion at work to help with his road to recovery.
The attempts at recovery were bumpy, though, and he was in and out of rehab. In 1997, a jet-ski accident left him with an addiction to the painkiller Vicodin. There were problems with alcohol, methadone and amphetamines, and in 2000 he was hospitalised with pancreatitis.
He once told BBC Radio 2 he didn't remember filming three years of Friends. "I was a little out of it at the time somewhere between seasons three and six."
After more attempts at treatment, he wrote in his memoir that he had been mostly sober since 2001 - "save for about 60 or 70 mishaps".
When Friends reached its final episode three years later, the cast, crew and audience were in tears. Perry said he felt nothing. "I couldn't tell if that was because of the opioid I was taking, or if I was just generally dead inside."
After such a big hit, it was hard for all the cast members to replicate that success.
Perry starred as a TV executive producer in Aaron Sorkin's Studio 60 on the Sunset Strip, and had memorable roles in The West Wing and Ally McBeal.
More sitcoms came and went. He played a sports talk radio host in Go On; a sports arena manager in Mr Sunshine; and a slovenly flatmate in The Odd Couple.
His films included crime caper The Whole Nine Yards and sequel The Whole Ten Yards with his friend Bruce Willis, plus romantic comedy Fools Rush In with Salma Hayek, and he played the older Zac Efron in 17 Again.
In 2016, he also wrote a play called The End of Longing - which the Times noted "explores his characters' search for love and commitment and the damage that can be wrought when those things continue to be absent from life".
Perry never found lasting love and avoided commitment.
'I need love but I don't trust it'
At first on Friends, he was "crushing badly" on Aniston, but those feelings evaporated, mainly because of "her deafening lack of interest".
He then got together with Julia Roberts when she co-starred on the show. But Perry's insecurities were not far from the surface and he claimed he was constantly convinced she was going to dump him.
"Why would she not? I was not enough; I could never be enough; I was broken, bent, unloveable. So instead of facing the inevitable agony of losing her, I broke up with the beautiful and brilliant Julia Roberts."
There were other relationships, including with Carrie Fisher's half-sister Tricia, actresses Lizzy Caplan and Yasmine Bleeth, and talent manager Molly Hurwitz.
But he said he found it hard to let people in. "I need love but I don't trust it. If I drop my game like Chandler and show you who I really am you might notice me - but worse you might notice me and might leave me, and I can't have that."
Meanwhile, his health problems reached a crisis point in 2018.
His colon "exploded" due to opiate abuse, requiring seven-hour surgery and meaning he was was given a 2% chance of making it through the first night. He did, but spent the next two weeks in a coma.
"I had all but killed myself," he later wrote. "I had never been a partier - taking all those drugs, and it was a lot of drugs, was just a futile attempt to feel better."
In his memoir, he recounted how he had spent $7m in total trying to get sober, attended 6,000 Alcoholics Anonymous meetings, had 15 stints in rehab, and gone to therapy twice a week for 30 years.
It was a high price for those deep-rooted insecurities that weren't fixed by huge fame, but he also used his own experiences to advocate for support for addicts.
He turned his $10m Malibu beach compound into Perry House, a men's sober living facility, in 2012, and the project received an award from the White House the following year.
He sold it two years later but said he was still committed to providing services for recovering addicts.
Now, following his death, that work is being acclaimed alongside the impact he made with his acting talent.
And he will long be fondly remembered for that by fans of Friends, on which he wore both his flaws and his natural comic brilliance on his sleeve.