- split breaks down the string into a list of values (('1', '2', '3', '4', '5')).
- For every element in the list,
- map transforms the element into a list consisting of the element and undef. (('1', undef)).
- map returns a list consisting of the aggregation of all the smaller lists (('1', undef, '2', undef, '3', undef, '4', undef, '5', undef)).
- The list returned by map is assigned to the hash.
By the way, here's a shorter solution:
my $keys = '1 2 3 4 5 6';
my %hash = $keys =~ /(\S+)()/g;
To use an environment variable, substitute $keys with $ENV{varname}.