### Table 1 $sth = $dbh->prepare("select * from master_table_1"); while (@row=$sth->fetchrow) { $query = "insert into back_table_2 (f1,f2,f3) VALUES ('@row[0]','@row[1]','@row[2]')" } ### Table 2 ### Table 1 $sth = $dbh->prepare("select * from master_table_2"); while (@row=$sth->fetchrow) { $query = "insert into back_table_2 (abc1,abc2,abc3) VALUES ('@row[0]','@row[1]','@row[2]')" }