perl replace command, stumped!

Ok,
I stole some code from a program that takess a hash of a password from PasswdMD5 and replaces it in the /etc/shadown file on a linux system. I run his program and it's fine. Well I took the same code and put it in another program that won't ask for prompgx and such and this code won't work:

perl -p -i.bk -e  's#^root:.*?:#root:$HASHLINUX:#' /etc/shadow

I validated $HASHLINUX has a good value in it. By not working I mean in the shadow file there is nothing in the column where the password hash value should be at.

Anyways I changed it to the below and it will work:

echo "perl -p -i.bk -e  's#^root:.*?:#root:$HASHLINUX:#' /etc/shadow" > /tmp/runpass
  sh /tmp/runpass

I really don't want to direct the statement to a external file and run it, but I cannot figure out why it won't work directly from the shell script.

Here's the whole procedure:

HASH=`/usr/local/bin/cryptpass $NEWPASS`
  HASHRHLX='$1$82gUYyNV$VWb5dxPAOqMFo9ZMWqFEW1'
  HASHRHLX=`echo "$HASH" | cut -f2 -d ":"`
  HASHLINUX=`echo "$HASHRHLX" | perl -p -e 's#\\$#\\\\\\$#g'`
  log "HASH = $HASH"
  log "HASHRHLX = $HASHRHLX"
  log "HASHLINUX = $HASHLINUX"
  echo "perl -p -i.bk -e  's#^root:.*?:#root:$HASHLINUX:#' /etc/shadow" > /tmp/runpass
  sh /tmp/runpass
  

Thanks for any help.

Single quotes tell the shell to not interpolate shell variables, but use the string literally.

perl -p -i.bk -e  "s#^root:.*?:#root:$HASHLINUX:#" /etc/shadow

That was the issue, thanks alot!