my %runmodes = ( config_item => 'regular', action1 => sub{ print "action = 1" }, action2 => sub{ print "action = 2" }, action3 => { config_item => 'special', subroutine => sub{ print "action = 3" }, }, ); sub get_config_item { my( $runmodes, $action ) = @_; my $config_item = $runmodes->{ config_item }; if( exists $runmodes->{ $action }{ subroutine } ) { # error line &{ $runmodes->{ $action }{ subroutine }}; $config_item = $runmodes->{ $action }{ config_item }; } else { &{ $runmodes->{ $action }} } return $config_item; } print ", ", get_config_item( \%runmodes, "action3" ), "\n"; print ", ", get_config_item( \%runmodes, "action1" ), "\n"; # OUTPUT # # action = 3, special # Not a HASH reference at str.pl line 22. #### my %runmodes = ( config_item => 'regular', action1 => { subroutine => sub{ print "action = 1" }}, action2 => { subroutine => sub{ print "action = 2" }}, action3 => { config_item => 'special', subroutine => sub{ print "action = 3" }}, }, );