$/ = ""; while () { s/^(.*)\n//; $key = $1; s/\n==(?=\n)/\n/g; $structure{$key} = $_; } __DATA__ key1 Here's a text block including blank lines ("encoded" as "==" in the perl script): == and here's a part of the block that's enclosed within "blank lines" == and here's the last part of the value for key1. key2 blah blah etc.