Hi Mareike,
if your intention would just be to "replace" an old PageRef with a (new) one, an idea would be to keep the exsting one but let it point to another content page (green) and just move the PageRef to the "new" location - but I assume that's not your use case... or might this also be an option?
If not: To my knowledge, there's no easy way to replace a PageRef just "everywhere".
Background: You would have to iterate not only into pages and sections but also into INPUT_DOMs (inline links), FS_CATALOGs (and their inner DOMs) and change all their FormData (change the value of all FS_REFERENCE's) so there would be quite some cases to handle.
Depending on "where most of those PageRefs [more precisely: The FS_REFERENCES] are": Iterating through pages/sections and replace the PageRef in those FS_REFERENCES that are "at the top level form" (=page templates and section templates) should be quite easy/generic. So it might be an approach to start with those "simple" cases.
Michael