package Foo::Config; use ... BEGIN { use Exporter; @EXPORT = qw/ &config /; # the following is the config data %config = ( dev => { A => {foo => 'dev_a'}, B => {this_is_not_foo => 'not_dev_b'}, _default => { foo => 'default_foo', database_env => 'dev_db', }, }, prod => { A => {foo => 'prod_a'}, B => {this_is_not_prod_foo => 'prod_b'}, _default => { foo => 'default_prod_foo', database_env => 'prod_db', }, }, _default => { A => { default_across_all_a_environments => 'def', }, _default => { the_same_everywhere => 1 }, }, # other stuff you want to run in the BEGIN block, i.e. set up the default environment. One thing i do is get a $environment variable based on the hostname. } #END BEGIN sub config($) { my $field = shift; if (exists $config{$environment}->{$sub_environment}{$field} ) { return $config{$environment}->{$sub_environment}{$field}; }; if (exists $config{'_default'}->{$sub_environment}{$field} ) { return $config{'_default'}->{$sub_environment}{$field}; }; if (exists $config{$environment}->{'_default'}{$field} ) { return $config{$environment}->{'_default'}{$field}; }; if (exists $config{'_default'}->{'_default'}{$field} ) { return $config{'_default'}->{'_default'}{$field}; }; return undef; } #### use Foo::Config; my $config_var = config('foo');