General "Replace" function replacement