replace ' with \' if it lies between two letters #### s/(?>=\w)'(?=\w)/\\'/g; #### s/\b'\b/\\'/g;