use warnings; use strict; my %bible; my $book; my $chapter; while () { chomp; if ( /^[^0-9]/ and !/chapter/i ) { $book = $_; } elsif (/chapter/i) { $chapter = $_; } else { my ( $verse, $words ) = split /\s/, $_, 2; push @{ $bible{$book}{$chapter}{$verse} }, $words; } } use Data::Dump; dd \%bible; __DATA__ Genesis chapter 1 1 In the beginning God created the heavens and the earth. 2 The earth was without form, and void; and darkness was on the face of the deep. And the Spirit of God was hovering over the face of the waters. chapter 2 1 Thus the heavens and the earth, and all the host of them, were finished. 2 And on the seventh day God ended His work which He had done, and He rested on the seventh day from all His work which He had done. Exodus chapter 1 1 Now these are the names of the children of Israel who came to Egypt; each man and his household came with Jacob: 2 Reuben, Simeon, Levi, and Judah; Matthew chapter 1 1 The book of the genealogy of Jesus Christ, the Son of David, the Son of Abraham: 2 Abraham begot Isaac, Isaac begot Jacob, and Jacob begot Judah and his brothers. John chapter 1 1 In the beginning was the Word, and the Word was with God, and the Word was God. 2 He was in the beginning with God.