#!/usr/bin/env perl use strict; use warnings; sub _validate_arguments { my ( $first_arg, $second_arg, $arg_count ) = @_; croak "Called without arguments." if $arg_count < 1; croak "Called with $arg_count arguments. Expected arguments: 1 or 2." if $arg_count > 2; croak "The first argument is not defined." if ! defined $first_arg; ... ... carp "The first argument refers to an empty list!" if ! @$first_arg; return; } sub my_function { my ( $first_arg, $second_arg ) = @_; _validate_arguments( $first_arg, $second_arg, scalar @_ ); return if ! @$first_arg; ... ... }