my @accounts = qw{ 118554 118555 118528 118529 118523 }; for ( @accounts ) { my $statement = " select distinct account, account_id, company, the_date from account_information where account_id = '$_' "; my $sth = $dbh->prepare( $statement ); $sth->execute; while ( my @row = $sth->fetchrow_array ) { print join( "\t", @row ) . "\n"; } }