my $my_path = $0; foreach my $path (split(/:/, $ENV{PATH})) { $my_path = "$path/$0" if (-f "$path/$0"); } #### my ($called_name) = $0 =~ m#/([^/]+)$#; { no strict; &{"mode_$called_name"}() if (defined &{"mode_$called_name"}); } sub mode_foo { # If program is called as "foo" } sub mode_moo { # If program is called as "moo" }