in reply to REGEX with input file

Your code should work already. I tried it and got the expected results.
use strict; use warnings; my $newUser ='$dummy'; while (<DATA>) { s/O_PREFIX=\w+/O_PREFIX=$newUser/; # s/(?<=O_PREFIX=)\w+/$newUser/; print; } __DATA__ if [ $YOU = 'frog' ] then export OUSER=TNN export CAR=SWs export O_PREFIX=ss export OS=corvette fi

And the output -
if [ $YOU = 'frog' ] then export OUSER=TNN export CAR=SWs export O_PREFIX=dummy export OS=corvette fi