in reply to 99 bottles of beer on the wall

You didn't provide a mechanism that changes "bottles" to "bottle" when $beer==1.

Oh, and $beer should be decremented at the moment you say "take one down".