sub handle_options { my ($hash, $options, $subref) = @_; foreach my $try (@$options) { next unless exists $hash->{$try}; $subref->( $try ); return; } die; } eval { handle_options( \%hash, \@options, \&do_something ); }; if {$@) { log_failure(); }