sub test1 { my $arg1 = shift; # but if you wanna print $arg2 then use '' instead of undef otherwise you get warning # and you do have use strict; use warnings; at the top right? :) my $arg2 = @_ >= 2 || ref $_[0] ne 'ARRAY' ? shift : undef; my $argrest = shift; print "arg1=$arg1, arg2=$arg2, argrest=@$argrest\n\n"; } test1('arg1', [qw/foo bar/]); test1('arg1', \@otherargs); test1('arg1', 'arg2'); test1('arg1', 'arg2', [qw/foo bar/]);