The Union had grabbed a 2-1 lead in the 87th minute on Aaron Wheeler's first career goal, a tally off a crossing pass from Sheanon Williams.
Then in stoppage time, Williams preserved Philadelphia's lead with a desperate clear of a Perez try off the goal line, even though replays showed it may have crossed the line.
But Perez got another chance in the 97th minute and this time made it count when he directed a header into the net after Union goalkeeper Zac MacMath couldn't haul in a free kick.
Walker Zimmerman also tallied for Dallas (8-3-6).
Amobi Okugos scored and Williams supplied two assists for Philadelphia (7-5-5).
Ray Liotta sues skin care company over use of likeness
Boston schools pull out free condoms over wrapping complaints