local $/ = '%%%'; # Assume 'FH' is input file, opened elswhere my @records; while(my $line = ) { $line =~ s/%%%//; # Remove any beginning or trailing whitespace # NOTE: Using \A and \z instead of ^ and $ is critical $line =~ s/\A \s* (.*?) \s* \z/$1/x; my %rec = split /[:\n]/, $line; push @records, \%rec; }