$product = "MOTOROLAx|xx|xx|x01-01-1900x|xYx|xx"; $product =~ s/(?<=\|)xx(?=(\||$)/x x/g; print "[ $product ]\n"; __END__ [ MOTOROLAx|x x|x x|x01-01-1900x|xYx|x x ]