# get column 0 from all result rows simultaneously.... my $results = $sth->fetchall_arrayref([0]); # error check here? # results are ref to array of hashes, so convert to array # we could avoid this and use "results" directly my @patterns = map { $_->[0] } @$results; for my $filename (@ARGV) { open my $f, "< $filename" or die "could not open $filename: $!"; my @lines = <$f>; for my $pattern (@patterns) { printf "%s has %d matches for pattern /%s/\n", $filename, scalar(grep /$pattern/, @lines), $pattern; } }