$string =~ s{(?: (?<===) \s+ | \s+ (?===) )}{}gx;