Well *actually* it does not. Your test string does not *actually* contain the edge cases ( xx at the begining and end of the string):o) If your test string had contained the edge cases you would no doubt have noted the following failure case.....
my $a = "xx|xx|xx|xxxx|xx|xxx|xx|xx|xx";
$a =~ s/(?<=\|)xx(?=(\||$))/x x/g;
xx|x x|x x|xxxx|x x|xxx|x x|x x|x x
$a =~ s/(?<=\|)|^xx(?=(\||$))/x x/g;
# and here is a way using the zero width boundary assertion \b
# that will match | ^ or $ but also matches any non aphlanumeric
# so would potentially fail on '|xx,xx|' type strings
# if they exist in practice as your real data is no doubt
# not really xx.....
$a =~ s/\bxx\b/x x/g;