in reply to search and replace regex return value

Could somebody please explain why the expected message is not printed from the code below. I assumed that the regex will return true when a replacement is done, but it makes the replacement and returns false

I assume it has to do with the value being a textvariable

Workaround is simple

my $target = $CFG{target} ; if ( $target =~ s/bar//xms ) { warn "expecting this message\n"; $CFG{target} = $target; } else { warn "not expecting this message\n"; }