It is during the parsing/compiling stage that it is complaining as it hasn't seen the sub declaration when it sees foo;. You can fix this by calling it as you have said above with foo(); or by predeclaring before you use it.
use strict;
...
sub foo;
...
foo;
...
...
sub foo
{ ... }