your sub flip won't work because you have missmathed parens. :)
More importantly, if you really want to optimize then don't use a subroutine there. Subroutines have a certain amount of overhead that you don't need here. I would just inline the $flop = !($flop)