Gonzalo Higuain had put Juve in front in Sunday's (AEST) Serie A finale but Perotti set up Nikola Kalinic's equaliser and put Roma ahead from the penalty spot before half-time at Allianz Stadium.
The winger gave fifth-placed Roma a cushion early in the second half as Juventus succumbed to a first home Serie A defeat since a 1-0 reverse to Napoli in April 2018, a run of 39 games.
It means champion Juve, which rested several players including Cristiano Ronaldo, finishes the campaign with back-to-back losses before aiming to overturn a Round of 16 deficit against Ligue 1 Lyon.
Higuain turned in from close range just six minutes in after pouncing on Adrien Rabiot's flick from Federico Bernardeschi's corner.
Juve was undone by a corner itself, though, as Kalinic nonchalantly converted Perotti's delivery.
Gianluca Frabotta, who was making a first Juve appearance, dragged wide, while fellow youngster Riccardo Calafiori rifled home at the other end, only for the ball to have gone out of play from the preceding corner.
Calafiori then drew the foul from Danilo for Perotti's penalty to find the bottom-right corner and put Roma ahead.
Perotti stretched the lead seven minutes into the second half, sweeping home inside the area, via a deflection off Merih Demiral, after collecting Nicolo Zaniolo's perfectly weighted pass.
Aaron Ramsey hit the post with a sweet effort and Higuain nearly found the bottom-left corner with a 20-yard strike.
But Roma had other chances too, with Davide Zappacosta shooting narrowly wide and Wojciech Szczesny made a couple of decent saves as Juve faltered before a huge UEFA Champions League showdown.