The 29-year-old spent two years on the books at the Emirates Stadium, having joined from Deportivo La Coruna in 2016 for £17million, but struggled to make an impression, scoring seven times in 21 appearances
Perez spent last season on loan with old club Depor, scoring seven goals, and appeared to have no future with the Gunners despite a change in management this summer.
The Hammers have now snapped up the Spanish forward for an undisclosed fee, with Perez joining Ryan Fredericks, Lukasz Fabianski, Issa Diop, Jack Wilshere, Andriy Yarmolenko, Fabian Balbuena and Felipe Anderson in making the switch to the London Stadium this summer.
"I'm very happy to be here at such an historic club," he told West Ham's website. "I'm very excited as West Ham are giving me the chance to stay in the Premier League and I'm very happy to be part of this new project.
"West Ham have great fans and play in an amazing stadium so to sign here brings me great joy. I'm very motivated."
Director of football Mario Husillos added: "He has great technical quality and can play as both the main striker or the second striker in a deeper role. He scores goals but can also create them and link well with the midfielders.
"His style is different from the other strikers we have available to us and that gives the manager more options for our attacking play."