in reply to Program enters infinite loop, can you see why?

It's one of the cases where quoting your variables can have an unexpected effect:
$x = "abc"; say 1 while $x =~ /c/g; say 2 while "$x" =~ /c/g;
will print a single 1, and an unlimited number of 2s.