Q:

Perl Function call

$\ = "\n";
sub foo
{
    print("one");
}
foo(); // mark1

sub foo
{
    print("two");
}
foo(); //mark2

On executing the above code, your output will be : two, two. As far as I understand Perl is a interpreter, so when foo(mark1) is called, shouldn't one get printed first, and when foo()(mark2) is called two must get printed. But why is two getting printed both the times, and please explain how?

A:

Because Perl isn't an interpreted language in the way that you understand it. Perl code is compiled before it is run. There's no separate compilation step for you to run, but the compiler parses and compiles all of the source code before starting to execute the program.
If you had included use warnings in your code, then you would have seen the following warning (before the output from the first function call):

Subroutine foo redefined at func line 12.

Which makes it pretty clear what is going on.
Oh, and by the way - // is not a comment in Perl. You wanted #.

