First, you shouldn't do that. See Why it's stupid to 'use a variable as a variable name'.
Second, why don't you have 'mailbox', 'subscribe' and 'country' as keys in a single hash? No need to have multiple hashes.
#!/usr/bin/perl
use strict;
use warnings;
use feature qw/ say /;
use Data::Dumper;
my @values = ('inbox', 'yes', 'NZ');
my %data;
$data{ $_ } = shift @values for qw/ mailbox subscribe country /;
say Dumper \%data;
__END__
Output:
[nick:~/monks]$ perl 1140269.pl
$VAR1 = {
'subscribe' => 'yes',
'country' => 'NZ',
'mailbox' => 'inbox'
};
Update: Or, if you have multiple records you can just put the code above in another loop. Below I make the hashref keys from a counter; perhaps you have user names or something that could be the keys.
#!/usr/bin/perl
use strict;
use warnings;
use feature qw/ say /;
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
my @records = ( [ 'inbox', 'yes', 'NZ' ],
[ 'inbox', 'no', 'UK' ],
[ 'outbox', 'yes', 'UK' ] );
my $href;
my $index = 0;
foreach my $record ( @records ) {
++$index;
$href->{ $index }->{ $_ } = shift @{ $record } for qw/ mailbox subsc
+ribe country /;
}
say Dumper $href;
__END__
Output:
[nick:~/monks]$ perl 1140269.pl
$VAR1 = {
'1' => {
'country' => 'NZ',
'mailbox' => 'inbox',
'subscribe' => 'yes'
},
'2' => {
'country' => 'UK',
'mailbox' => 'inbox',
'subscribe' => 'no'
},
'3' => {
'country' => 'UK',
'mailbox' => 'outbox',
'subscribe' => 'yes'
}
};
The way forward always starts with a minimal test.