in reply to something about improving code...

how about
sub flip { !($_[0]) }
and in your main body just do
$flop=flip($flop);