foreach () { my $re = qr/($book|$title)/; next unless /$re/; push @matches, [$1, $_, $re]; print; }