# After the initial, usual stuff I query mySQL using # DBI and extract employee id numbers and their names # for an array and a hash. while (@emp_list = $sth->fetchrow_array()) { push(@emps, $emp_list[0]); $employees{$emp_list[0]} ="$emp_list[1]"; } $sth->finish(); my @days = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri'); foreach $emp_id(@emps) { print "Employee: ", $employees{$emp_id}, "\n"; print "Employee ID: ", $emp_id, "\n"; foreach $wkday(@days) { $sql_str = "SELECT emp_name, field2, field3 FROM table1 WHERE emp_id='$emp_id' AND wkday='$wkday'"; $sth= $dbh->prepare($sql_str); $sth->execute(); @schedule = $sth->fetchrow_array(); } print @schedule; # Actually I break the @schedule up nicer than this. }