Why does this statement not work when it is bound to the front of the line? Run the following code and you will see that the first test passes, and the second, which is changed only with the help of the binding ^, fails.
use Test::More tests => 2;
my $s = '/123/456/hello';
$s =~ s{(?<=/)\d+(?=/\d+/hello)}{0};
is($s, '/0/456/hello', 'unanchored');
$s = '/123/456/hello';
$s =~ s{^(?<=/)\d+(?=/\d+/hello)}{0};
is($s, '/0/456/hello', 'anchored');
Moving ^to a look-behind statement is not an option for me (this is a very simplified example), but it fixes the problem. I found an alternative way to do what I want, but I am curious why this approach did not work. I tested this on perl 5.8.8 and perl 5.10.0.
source
share