use strict; use warnings; use feature 'say'; use Carp qw( croak ); sub test_function { @_==1 or croak "oops: this function takes exactly one argument"; 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 croak "oops: argument is not defined"; } say "Calling test_function with no arguments:"; eval { test_function(); }; say $@; say "Calling test_function with an undefined argument:"; eval { test_function(undef); }; say $@;