#!/usr/bin/perl use strict; use warnings; my %structure; { local $/ = ""; # input record separator = empty string for "paragraph mode" while () { s/^(.*)\n//; # first line is key string $structure{$1} = $_; } } print "key: $_ / value:\n$structure{$_}\n----\n" for ( sort keys %structure ); __DATA__ first_key Here's some data to go with the first key key_3 Third key gets this part key number 2 This element of %structure has spaces in the hash key.