Yes, this is documented in perlop:
If the PATTERN evaluates to the empty string, the last successfully matched regular expression is used instead. In this case, only the g and c flags on the empty pattern is honoured - the other flags are taken from the original pattern. If no match has previously succeeded, this will (silently) act instead as a genuine empty pattern (which will always match).
If you want to $pat = ''; /$pat/ to match only empty strings, then add $pat = qr/^\z/ if not length($pat);
If you want to $pat = ''; /$pat/ to match everything, then add $pat = qr/.*/ if not length($pat);
In reply to Re: s/// with an empty pattern uses the previous pattern of a s///
by ikegami
in thread s/// with an empty pattern uses the previous pattern of a s///
by ckeith100
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |