use strict; use warnings; use Data::Dumper; my $test =<{title} = $1; } elsif ($line =~ /$re_author/) { $book->{author} = [ $1, $2 ]; } elsif ($line =~ /$re_publisher/) { $book->{publisher} = $1; } } #push the final book push @answers, $book; print Dumper(\@answers);