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.