in reply to Count replaces in search and replace

That kind of code is very susceptible to performance problems. Make sure you're not compiling $replace over and over again.