in reply to why such an error happened?

I think something else is going on.

Consider these three examples (note that the example string is different):

>perl -wMstrict -le "my $chr; $chr = \"x this and that y\"; $chr =~ s/(this|that)|(\w+)/$1\U$2/g; print \"$chr\n\"; " Use of uninitialized value in concatenation (.) or string ... Use of uninitialized value in concatenation (.) or string ... Use of uninitialized value in concatenation (.) or string ... X this AND that Y
and
>perl -wMstrict -le "my $chr; $chr = \"x this and that y\"; $chr =~ s/(this|that)|(\w+)/\u$1\E$2/g; print \"$chr\n\"; " Use of uninitialized value in concatenation (.) or string ... Use of uninitialized value in concatenation (.) or string ... x This and That y
and
>perl -wMstrict -le "my $chr; $chr = \"x this and that y\"; $chr =~ s/(this|that)|(\w+)/\u$1\E\U$2/g; print \"$chr\n\"; " X This AND That Y
As mentioned before, either one or the other (but not both) of the capturing groups will be satisfied, so either $1 or $2 (but not both) will be defined. In all the all examples, the regex matches five times, twice for (this|that) and three times for (\w+), but various numbers of warnings are printed.

The number of warnings depends on which capture variable is defined and which capture variable is 'transformed' by \u or \U in the replacement string. (A replacement string without any \u or \U transformations yields five warnings.)

When both $1 and $2 are transformed in some way within the replacement string, there are no warnings. Apparently, and surprisingly (to me at any rate), the \u and \U transformations in the replacement string suppress the warnings I expected.

Offhand, I can't think why this is the case.

Update: Corrected a swapped word order.