Add function prototypes. Change the way functions are called and either alter their declaration order or predeclare them so perl can check the prototypes.