You can work around it by either not using -x, or using a newline
instead of a space after [^#]+
use 5.10.0;
my $BAR = 'bar';
my $BAR_REGEX = qr{ $BAR [^#]+
-D $BAR }xms;
say $BAR_REGEX;
my $BAR2_REGEX = qr{$BAR[^#]+-D$BAR}ms;
say $BAR2_REGEX;
says:
(?msx-i: bar [^#]+
-D bar )
(?ms-xi:bar[^#]+-Dbar)