It's not a bug in Perl but a bug in your expectations. The empty RE // always matches, see perlre resp. perlop. And the first match has nothing to do with it, as removing it still produces all matches:
#!/usr/bin/perl my @strings = ('testing','','testing','testing'); foreach my $string (@strings) { my $q = $string; my $test = 'testing'; warn "$test =~ /$q/?"; warn $test =~ /\Q$q\E/; } __END__ testing =~ /testing/? at tmp.pl line 8. 1 at tmp.pl line 9. testing =~ //? at tmp.pl line 8. 1 at tmp.pl line 9. testing =~ /testing/? at tmp.pl line 8. 1 at tmp.pl line 9. testing =~ /testing/? at tmp.pl line 8. 1 at tmp.pl line 9.
Update: Actually, while my reply is not untrue, the real cause is told by Anonymous Monk below. The empty match will repeat the last match.
In reply to Re: Perl bug or feature?
by Corion
in thread Perl bug or feature?
by yegg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |