Modifying a file before storing

Upgrading an old app using paperclip and I’m struggling to solve this problem.

We allow uploads of html files. Before storing, we insert markup into the files.

I’ve tried using derivatives, but they aren’t quite what I want. I don’t need to copy the file, I just want to update the file before saving it off. The name needs to remain the same.

Any suggestions would be helpful.