in reply to global string replace

Use a look-ahead assertion. It looks ahead, but doesn't advance the position:
s/(^|\*)X(?=\*|$)/$1$NEW/g # ~~~
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]