use strict; use warnings; use feature 'say'; sub test_function { my $ref = shift; # this function takes one argument, a ref to an ARRAY # Note: you could do extra manual checking of function arguments. # Not necessarily recommended: shown for educational purposes. defined($ref) or die "oops: you did not pass any arguments"; @_ and die "oops: this function takes exactly one argument"; } say "Calling test_function with no arguments:"; eval { test_function(); }; say $@; say "Calling test_function with a single undefined argument:"; eval { test_function(undef); }; say $@;