#! perl -slw use strict; use DBI; my $dbi = DBO->connect( ... ); ## Prepare multiple statments for different DBs my @sth = map{ $dbi->prepare( ... ) } 1 .. $DBS; ## Piped open pre-filters data thru tail and grep -f my $pid = open TAIL, "tail -f /path/to/the/log | grep -Pf patterns.file |" or die $!; my @collected; ## Uploading medium sized batches of data is usually quickest while( ) { ## Decide which DB this line is destined for my $dbn = m[some selection criteria]; ## and put it into that batch push @{ $collected[ $dbn }, $_; ## subselect if you dont want the whole line ## And when that batch reaches the optimum(?) size, upload it if( @{ $collected[ $dbn ] } >= 100 ) { ## 100 is a guess $sth[ $dbn ]->execute( @{ $collected[ $dbn ] ); @{ $collected[ $dbn ] } = (); } }; close TAIL;