wine@localhost]$ perl -pe 's/(")[^\1]*\1/check/g' "strings 1" "string 2" # input check #output #### wine@localhost]$ perl -pe 's/"[^"]*"/check/g' "string 1" "string 2" check check #### wine@localhost]$ perl -pe 's/(")[^$1]*$1/check/g' "string 1" "string 2" Unmatched [ before HERE mark in regex m/(")[ << HERE ^]*/ at -e line 1, <> line 1. #### wine@localhost]$ perl -pe 's/(a)[^\1]*\1/check/g' abbbba abbbbbbbba check #### # ("|'"'"') is a complex bash escape for ("|') wine@localhost]$ perl -pe 's/("|'"'"')[^\1]*\1/check/g' "aaa" 'aaa' check check #### perl -pe 's/("|'"'"')[^\1]*\1/check/g' "aaa" "aaa" check #### wine@localhost]$ sed 's/\(a\)[^\1]*\1/check/g' abbbba abbbbbbbba check