sub cmd_move { my ($package, $direction) = @_; print "You start to walk $direction, but suddenly remember that Grues live there\n"; } while () { chomp; my ($cmd, @args) = split(/\s+/, $_); $cmd = "cmd_$cmd"; if (($cmd !~ /^\w+$/) || !main->can($cmd)) { print "Unknown command. Try again.\n"; } else { main->$cmd(@args); } } #### package Commands; sub cmd_move {....}; . . . package main; while () { ... if (Commands->can($cmd)) {...} }