while ( my ( $k, $v ) = each %opts ) { for ($k) { if (/h/) { ...; } elsif (/v/) { ++$verbose; } elsif (/i/) { $infile = $v; } else { die "*** BUG: no handler for -$k.\n"; } } } #### 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}}; }