Use this tool, which is written in Perl - with quite a lot of bells and whistles - oldie, but goodie:
http://unixgods.org/~tilo/replace_string/
Features:
- do multiple search-replace or query-search-replace operations
- search-replace expressions can be given on the command line or read from a file
- processes multiple input files
- recursively descend into directory and do multiple search/replace operations on all files
- user defined perl expressions are applied to each line of each input file
- optionally run in paragraph mode (for multi-line search/replace)
- interactive mode
- batch mode
- optionally backup files and backup numbering
- preserve modes/owner when run as root
- ignore symbolic links, empty files, write protected files, sockets, named pipes, and directory names
- optionally replace lines only matching / not matching a given regular expression
This script has been used quite extensively over the years with large data sets.