$CONFIG = { my_github => { email => "me\@example.com", password => "PaSsWoRd" }, my_sftp => { domain => "example.com", password => "PaSsWoRd", username => "sftpuser" } }; #### use warnings; use strict; use Data::Dumper; my $file = '/path/to/config2.pm'; my $templ = '/path/to/config2.pm.templ'; our $CONFIG; if (not my $return = do $file) { die "couldn't parse $file: $@" if $@; die "couldn't do $file: $!" unless defined $return; die "couldn't run $file" unless $return; } for my $hash (values %$CONFIG) { for my $val (values %$hash) { $val = 'redacted'; } } open my $fh, '>', $templ or die "$templ: $!"; print {$fh} Data::Dumper->new([$CONFIG],['$CONFIG']) ->Useqq(1)->Sortkeys(1)->Quotekeys(0)->Dump; close $fh; #### $CONFIG = { my_github => { email => "redacted", password => "redacted" }, my_sftp => { domain => "redacted", password => "redacted", username => "redacted" } };