sub unpack_named_first { my ($pos1, $pos2 ,%arg) = @_; # unpack my ($name1, $name2) = @arg{'name1','name2'} $pos1 // die("Missing arg!"); # obligatory $pos2 //= 42; # default $name1 // die("Missing arg!"); # obligatory #$name2 # optional # ...etc }