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" }