use non-interactive functions instead of replace-regexp

replace-regexp gives compilation warnings which is annoying.
Also a counter was added to account for a growing region.
Thanks for the great function.