# instead of my $class = shift; my $self = bless {}, ref($class) || $class; # try my $self = bless {}, ref($_[0]) || @_ #### sub foo { # some stuff open my $fh, @_; return $fh; } #### sub foo { # some stuff my $fh; if (@_ == 1) { open $fh, $_[0]; } else { open $fh, $_[0], $_[1], @_[2..$#_]; } return $fh; }