in reply to something about improving code...

You wrote:
> i tried > sub flip { $@_[0] = !($@_[0] };
So close. :) Try this:
sub flip { ${ $_[0] } = !${ $_[0] } }
Alternatively, check out Tie::FlipFlop on CPAN. It uses tie to automatically take care of a flipflop state, and it lets you use other values than 0 and 1, as well. It's very cool. And you also don't have to call a flip function, because tie handles it all automagically.

Here's a snippet from the docs:

use Tie::FlipFlop; tie my $flipflop => Tie::FlipFlop => qw /Red Green/; print $flipflop; # Prints 'Red'. print $flipflop; # Prints 'Green'. print $flipflop; # Prints 'Red'.