Your problem hinges on the idea that $0 in perl is like $ARGV[0] in C. The perl variable $0 is actually the name of the program that is running. The command line args are stored in @ARGV. So you really want $ARGV[0] (like in c).
Try running this code:
use strict;
use warnings;
{
print "\$0 = $0\n";
print "\$ARGV[0] = $ARGV[0]\n";
}
Assume that the name of this script is arg_test.pl, run the command:
>perl -w arg_test.pl foo
which yields this output:
$0 = arg_test.pl
$ARGV[0] = foo
The rest of your scripts behaviour should become clear.