while ( my ( $k, $v ) = each %opts ) { state %dispatch = ( h => sub{...;}, v => sub{ ++$verbose;}, i => sub{ $infile = $v; }, ); die "*** BUG: no handler for -$k.\n" if !exists $dispatch{$k}; &{$dispatch{$k}}; }