my @records = (); my %current = (); while () { my @line = split /\s*\|/; if ($line[0] =~ /^\S/) { if (keys %current) { push @records, {%current}; %current = (); } @current{qw/name var1 var2 var3/} = @line; } elsif ($line[0] =~ /^ (.*)/) { $current{name} .= $1; } else { # Deal with the other lines as you need to.. } } push @records, {%current};