package Foo::Bar; sub import { my %handlers = ( DEFAULT_XFR => \&set_xfr, NO_LOG => \&disable_logging ); my @args; for my $i ( 1 .. $#_ ) { push(@args, [ $_[$i], $i ]), next if $_[$i] eq 'DEFAULT_XFR'; push(@args, [ $_[$i], $i ]), next if $_[$i] eq 'NO_LOG'; } # two loops because we don't want to splice @_ while looping over it foreach my $arg ( @args ) { if ( exists $handlers( $arg->[0] ) ) { $handlers( $arg->[0] )->( $arg->[1], @_ ); } } Foo::Bar->export_to_level( 1, @_ ); } sub set_xfr { my $index = shift; if ( defined $_[$index + 1] and $_[$index + 1] =~ /^([A-Z]\d{4,5})$/ ) { $Foo::DEFAULT_XFR = $1; splice @_, $index, 2; } else { $Foo::DEFAULT_XFR = 'H00293'; splice @_, $index, 1; } } sub disable_logging { # same concept; }