in reply to Re^3: no way it's not a bug of Perl
in thread I thought I found a bug of Perl

I expected it just do nothing, But it's more useful to take last matched pattern.

Replies are listed 'Best First'.
Re^5: no way it's not a bug of Perl
by ikegami (Patriarch) on Jul 14, 2024 at 13:17 UTC

    s/(?:)// will do nothing (or rather, replace one-zero length string with another zero-length string). So, if you have a possibly-empty pattern in a variable, you could use

    s/(?:$pat)//

    or

    my $re = qr/$pat/; s/$re//

    The latter was buggy before 5.18 as it resulted in the same as s/// when $pat contained an empty string.

      glad to learn that there is a way to suppress the urge of abnormal behavior.