use warnings; use strict; use Data::Dumper; $Data::Dumper::Sortkeys = 1; my %info; while () { chomp; my ($k, $v) = split /=/; $info{$k} = $v if length $v; } print Dumper(\%info); __DATA__ a=5 b=6 c= d=7 #### $VAR1 = { 'a' => '5', 'b' => '6', 'd' => '7' #### while () { chomp; my ($k, $v) = split /=/; $info{$k} = (length $v) ? $v : 666; }