in reply to multiple conditions while loop

I am not sure what you meant but from what I understood you could have one function that takes a parameter representing a table. So, something along the lines of

sub write() { my $STH = shift; while( @data = $STH->fetchrow_array() ) { ## processing goes here } }

And call that same function for each table.