in reply to Re^2: In place replace, ignoring between quotes
in thread In place replace, ignoring between quotes

Yes, this is a state machine. I spend a lot of time coding in Verilog, where toggling a bit is a natural part of the language. I guess this would be cleaner in Perl:
$out = $out ? 0 : 1 if $_ eq '"';

I do not know why Perl sets $out to undef.