use strict; use warnings; use Data::Dumper; my $test =<{title} = $1; $b->{author} = [$2,$3]; $b->{publisher} = $4; $b->{year} = $5; } ], [ qr/^Title: (.*?), Author: (\w+) (\w+), Publisher: (\w+)$/, sub { my $b = shift; $b->{title} = $1; $b->{author} = [$2,$3]; $b->{publisher} = $4 } ], [ qr/^Title: (.*?), Author: (\w+) (\w+)$/, sub { my $b = shift; $b->{title} = $1; $b->{author} = [$2,$3] } ], [ qr/^Title: (.*?)$/, sub { my $b = shift; $b->{title} = $1; } ], [ qr/^Author: (\w+) (\w+)$/, sub { my $b = shift; $b->{author} = [$1,$2];}], [ qr/^Publisher: (.*?)$/, sub { my $b = shift; $b->{publisher}= $1; } ], ); my @answers; for my $book_src (@books) { my $book = {}; for my $re (@res) { my $reg = $re->[0]; if ($book_src =~ /$reg/mgc){ &{$re->[1]}($book); } } push @answers, $book; } print Dumper(\@answers); __END__ $VAR1 = [ { 'author' => [ 'Salman', 'Rushdie' ], 'title' => 'The Moor\'s Last Sigh', 'publisher' => 'Foo' }, { 'author' => [ 'Arundhati', 'Roy' ], 'title' => 'The God of Small Things', 'publisher' => 'Bar' }, { 'author' => [ 'Salman', 'Rushdie' ], 'title' => 'The Moor\'s Last Sigh' } ];