$string=~/([^Y]+)X/$1/g;