in reply to speeding up a regex

I'd recommend two minor changes --

  1. Put the case insensitive flag at the top, rather than for each iteration of the loop. (I haven't benchmarked it, but I'm just one to do as much repetitive stuff before the loop, if at all possible)
  2. Use a single regex for matching, as you don't seem to be doing anything different based on which term within the loop matched.*

* I know, that's not specifically true, as with your case, you can match each item in the list once, but I'm making a general assumption that your items look to be SQL statements, and if they're single statements, they're most likely mutually exclusive, so long as you don't have sub queries

I'd probably rewrite it something like:

my $pattern = qr/\b(?:create|drop|delete|update|insert)\b/i; # open a database connection here (using Sybase::DBD) and # create a statement string to execute $sth=$dbh->prepare("@sqlstatement"); $sth->execute; while ($data = $sth->fetchrow_arrayref()) { next if($data->[10] =~ /tempdb/i); if ($date->[13] =~ $pattern) { print "$data->[3] $data->[9] $data->[10] $data->[13]\n"; } }

You can also use perl's foreach loops to deal with iterating through a list, when the actual index isn't important. (yes, I know, it can be called with 'for', but I always think of C's for loops when I use 'for')