Loop with sed command to replace line with sed command in it

Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line.

Line in the many scripts I'm trying to replace:

       if (ps -ef | grep $(cat $PID_FILE) | grep -v grep); then

I'm trying to replace that with:

       if (ps -C java -o pid,cmd | grep ${SERVER_NAME}| sed 's/^[ ]//g' | cut -d' ' -f1); then

Here is the script I have:

#!/bin/sh
for i in `find . -name script1 -o -name script2 -o -name script3 -o -name script4`
        do
        dirVar=`dirname $i`
        fileVar=`basename $i`
        modFileVar=`basename $i .ORI`
        homeVar='/home/chris/tmp'
        echo ${dirVar}/${fileVar}
        cd $dirVar
        cp $fileVar $modFileVar
        if [ -f $fileVar ]
        then
        echo "file exists performing perl line on file $fileVar"
        sed -i "s/ps -ef | grep \$(cat \$PID_FILE) | grep -v grep/ps -C java -o pid,cmd | grep \$\{SERVER_NAME\} | sed 's/^[]//g' |  cut -d' ' -f1 | grep -v grep/" $modFileVar
        chmod 700 $modFileVar
        fi
        echo "File Var $fileVar"
        echo "Modded File Var $modFileVar"
        cd $homeVar
        done
exit

I get this error with the above script:

sed: -e expression #1, char 102: Unknown option to `s'

Obviously I get it over and over again b/c I'm doing it in a loop.
I was also trying this with perl, and the one line of perl that I was trying was:

perl -ne 's/ps -ef \| grep \$\(cat \$PID_FILE\) \| grep -v grep/ps -C java -o pid,cmd \| grep \${SERVER_NAME} \| sed 's/^[]//g' \| cut -d -f1 \| grep -v grep' -ne "s/-d/-d' '/; print" $fileVar >> $modFileVar

With the perl line I get this error:

Warning: Use of "-d" without parentheses is ambiguous at -e line 2.
syntax error at -e line 2, near "s/-d"
  (Might be a runaway multi-line // string starting on line 1)
Execution of -e aborted due to compilation errors.

I have no real preference as to which way to get it working, just that I need to get it working and have been stuck for quite some time now.

probe to chage this line

sed -i "s/ps -ef | grep \$(cat \$PID_FILE) | grep -v grep/ps -C java -o pid,cmd | grep \$\{SERVER_NAME\} | sed 's/^[]//g' |  cut -d' ' -f1 | grep -v grep/" $modFileVar

for this one:

sed 's/ps -ef | grep \$(cat \$PID_FILE) | grep -v grep/ps -C java -o pid,cmd | grep \${SERVER_NAME} | sed "s\/\^\[ \]\/\/g | cut -d" " -f1 | grep -v grep/'  $modFileVar