Example1 work fine when I want to replace OLD_TEXT with NEW_TEXT ( its replace also all special characters as $@^%)(_+`:; etc ..)
example1
export OLD_TEXT='$$OLD_WORD$$'
export NEW_TEXT='$$NEW_WORD$$'
perl -pe 'next if /^#/; s/\Q$ENV{OLD_TEXT}\E/$1$ENV{NEW_TEXT}$2/g' file
on example2
I add the "[[:^alnum:]]" in the perl syntax in order to ignore TEXT that start with alpha numeric characters or end with alpha numric characters
but as all see it doesn't work why?
remark: alpha numric characters means numbers OR [a-z][A-Z]
Real Example
#example2 on LINUX machine:
more file
ABC$$OLD_WORD$$ABC
$$OLD_WORD$$
.
perl -pe 'next if /^#/; s/(\Q|[[:^alnum:]])$ENV{OLD_TEXT}(\E|[[:^alnum:]])/$1$ENV{NEW_TEXT}$2/g' file
$$NEW_WORD$$ABC$$$NEW_WORD$$$$$NEW_WORD$$OLD_$$NEW_WORD$$WORD$$$NEW_WORD$$$$$NEW_WORD$$ABC
.
Example what I should get:
more file
ABC$$OLD_WORD$$ABC
$$NEW_WORD$$