my %sheets; $sheets{$_} = $workbook->add_worksheet($_) for qw( AP NAP ); my %column_headings = ( AP => [qw( Login UserName Group ... )], NAP => [qw( Login UserName LDAP-Status ... )], ); foreach my $sheet_name (keys %column_headings) { my $col = 0; foreach my $col_name (@{$column_headings{$sheet_name}}) { $sheets{$sheet_name}->write(0, $col++, $col_name, $heading_format); } }