Assuming your XML line is stored in the $line variable, the substitution itself is easy:

Code

$line =~ s/<ref id="ref0152">/<ref id="R1>/g;

Although I guess you probably really want the new string to be <ref id="R1"> rather than <ref id="R1> as you wrote, in which case you just have the missing double quote after the R1 in the code line above.

I leave it to you to build the other substitution, I think it should be fairly obvious.