sub foo { my $arg_count = 3; if ($arg_count != @_) { die "Incorrect number of arguments to foo"; } #... else do stuff }