Panama advanced into a Wednesday semi-final of the biennial North American, Central American and Caribbean regional tournament against the winner of a later match between defending champion Mexico and Trinidad and Tobago.
Jose Ciprian gave Cuba the lead in the 21st minute, but four minutes later Torres equalised from the penalty spot.
Torres gave Panama the lead for good with a goal in the 38th minute but the game turned when Cuban forward Ariel Martinez was shown a red card in the 58th minute after a nasty foul on Perez.
Panama's Carlos Rodriguez followed with his first intrernational goal in the 67th minute, Perez added goals in the 78th and 87th minutes and Jairo Jimenez netted his first international strike in the 84th minute.
Sunday's quarter-finals at Baltimore send the hosts USA against El Salvador and Honduras square off with Costa Rica. They will meet in Wednesday's other semi-final. The winners of the CONCACAF regional crown will meet the 2015 Gold Cup winners to decide a berth in the 2017 FIFA Confederations Cup.