sed back reference error

I am trying to change a single line of a special file whose comment character is ! to show a path to the file in the comment. such as:

!!HFSS and mcm path:     \Signal_Integrity\Package_SI\Section_Models\C4toTrace\28nm\D6HS\SLC_5-2-5\GZ41_ICZ\NSSS\

to a different path and replace the !!HFSS and mcm path: text.

here is my code:

path='!! HFSS and mcm path: '$(pwd)

for file in $(find . -name "*s[48]p*")
do
  old=$(grep '!! HFSS\|!!HFSS' $file)
  sed -i "s@$old@$path@" $file
done

I get the following error for some but not all files!

sed: -e expression #1, char 260: Invalid back reference

can someone please help explain why it works for some files but not others?
Thanks,
Mike

My guess is that your strings contains backslashes followed by numbers, which gets interpreted as a back reference. Note that sed substitute functions does not use strings, but rather regular expressions.

A safer way would be to use fixed strings, for example

path='!! HFSS and mcm path: '$(pwd)
awk -v p="$path" '/!! *HFS/{$0=p}1' file