in reply to Detecting Subroutine Input Type

This problem is not solvable without placing restrictions on what can be in the array or how the array reference looks.

In your solution above, you distinguish based on number of arguments passed, which prevents you from passing an array of one element (which may or may not be just fine for your purpose).

You could instead choose to check the ref type of the parameter: if (ref $_[0] eq "ARRAY") { ... } else { ... } which would prevent you from passing an array whose first element was an array reference. (Variations on this involve UNIVERSAL::isa($_[0], "ARRAY") or calling an isa method on an object or doing an array dereference in an eval block to see if it fails; this subproblem of "what is an array reference" also has no perfect solution.)

Or combine both the check for one element and the check for an array ref.

There are also prototypes; if you promise to not use them as if they were what other languages call prototypes,

you can give your sub a (\@) prototype; then just call it as foo(@array) and $_[0] will automatically be a ref to the array; if you want to pass an array ref instead, say sub(@$arrayref), which will place the reference in $_[0] (without the actual overhead of expanding the array into a list).

All in all, it's best to document what your routine expects and take only that input; do you really need to accept both?