in reply to Avoid eval() / dynamic regular expressions

Whilst you'll get some gains from creating a sub that processes one line at a time, you'll have to pay for (some of) it with the overhead of calling a sub for every line.

Since you're already dynamically generating a sub, why not just wrap up the entire processing including the loop into the sub and just call it once:

open(REGEX, "<$filter"); while(<REGEX>) { next if ($_ =~ m/^\s*#.*$/); chomp; $regex .= "$_, "; } close(REGEX); my $code = eval <<EOC sub { for ( \@_ ) { chomp; $regex; ## Note: using $_ implicitely is faster ## extract fields and do sql INSERT ... } } EOC $code->( split /^/, $lines );

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"I'd rather go naked than blow up my ass"