per-file replacement function