Global way to modify output?

We have a number of core systems and third-party software systems on the website and we need to temporarily be able to modify a bit of a header if a certain cookie exists.

This would be a lot of work to build in the logic/code into all of the systems especially since it isn’t a permanent change.

I found auto_append_file but it doesn’t look like it can MODIFY the existing output?

Is there any way I could easily do something like a drop-in solution that would be able to find/replace a block of HTML after checking for a cookie?

look up ob_start();

However the whole thing seems a bit hacky to me.