open(FILE,"<$file") or die $!; # always check for the error condition! while (my $line = ) { if ($line =~ m/\[(.*)\]/) { push @art, { item => $1 }; } elsif ($line =~ m/^(\w+)\s*=\s*(.*?)\s*$/) { # the \s*'s ignore leading and trailing whitespace. $art[-1]->{$1} = $2; # [-1] references the last item in the array; i.e. what you just pushed on there } } close FILE;