Turns out that AnyEvent was leaking a reference to its internal state through $_ and my attempt to read a line from a file would overwrite that variable instead of creating a newly scoped $_.
Global variables, not even once.
why would a while use global variable by default?
Why would $_ ever be not lexically scoped?
@wolf480pl I don't know the file details, this is pre-5.8 stuff, but I'm guessing it went something like this: Historically, $_ was a global variable (still is, I think. Perl is built on globals...), then at some point it was made possible to temporarily overwrite a global variable within a certain scope, functions called from that scope would also observe that change but functions outside wouldn't (this is what 'local' does, real handy feature).
Why does a while loop not localize $_? Not sure, I'm guessing its so that you can still access the value from the last iteration, maybe a backwards compat thing. for/foreach loops do localize $_.
A lonely little town in the wider world of the fediverse.