$line =~ s/^ ( (?= .*? $regex_1 ) .*? $regex_1 #FIRST PRIORITY | (?= .*? $regex_2 ) .*? $regex_2 #SECOND PRIORITY ) /something/gmx;