my $file = '/home/guest/sampir.txt'); open (PIR, '<', $file) or die "Can't read '$file': $!\n"; my @arr = (); my $se = []; # anonymous record array while() { chomp; if (/^(\w+)\s+/) # new field identifier, followed by blanks { push @$se, $_; } elsif (s/^\s+/ /) # if we can strip leading blanks, # it's a continuation line { $se->[-1] .= $_; # append to last field of this record } elsif(/^\w+$/) # must be the last field of the record { push @$se, $_; # save the last field push @arr, $se; # save the record array reference $se = []; # and make a new array reference for the next record } else { die "Unknown line type at line $. of '$file'\n"; } }