my %hash = ((split / /, $str), $str =~ y/ / / % 2 ? () : undef); #### $ perl -wMstrict -MData::Dump -e 'my $s = "a 1 b 2 c 3 Odd"; my %h = ((split / /, $s), $s =~ y/ / / % 2 ? () : undef); dd \%h' { a => 1, b => 2, c => 3, Odd => undef } $ perl -wMstrict -MData::Dump -e 'my $s = "a 1 b 2 c 3 Even 4"; my %h = ((split / /, $s), $s =~ y/ / / % 2 ? () : undef); dd \%h' { a => 1, b => 2, c => 3, Even => 4 }