use warnings; use strict; my ($file, $thing); my %arg_table = ( -f => sub { $file = shift; }, -t => sub { $thing = shift; }, default => sub { die "bad param"; }, ); while (my @args = splice @ARGV, 0, 2){ if (defined $arg_table{$args[0]}){ $arg_table{$args[0]}->($args[1]); } else { $arg_table{default}->(); } } print $file if defined $file; print $thing if defined $thing;