our $lname; my $sth = $dbh->prepare(<execute or die $sth->errstr; my $previous_supervisor = ''; while (my $aref = $sth->fetchrow_arrayref) { my ($sup_fname, $sup_lname, $sup_title, $emp_fname, $emp_lname, $emp_title) = @$aref; # control-break: if a new supervisor is found, skip a few lines and add a header my $current_supervisor = "$sup_fname $sup_lname"; if ($current_supervisor ne $previous_supervisor) { $R += 3; $C = 0; $worksheet0->write($R, $C++, "SUPERVISOR: ", $format_HEADER); $worksheet0->write($R, $C++, $current_supervisor, $format_HEADER); $R++; $C=0; $worksheet0->write($R, $C++, "First Name", $format_COL_HEADER); $worksheet0->write($R, $C++, "Last Name", $format_COL_HEADER); $worksheet0->write($R, $C++, "Title", $format_COL_HEADER); $worksheet0->write($R, $C++, "Supervisor", $format_COL_HEADER); } # Add employee to sheet $R++; $C=0; $worksheet0->write($R, $C++, $emp_fname, $format_NORMAL); $worksheet0->write($R, $C++, $emp_lname, $format_NORMAL); $worksheet0->write($R, $C++, $emp_title, $format_NORMAL); $worksheet0->write($R, $C++, $emp_supervisor, $format_NORMAL); }