# open three file handles, for NT page, UNIX page, MAIL page foreach my $class ( sort keys %classHash ) { foreach my $status ( sort keys %{$classHash{$class}} ) { if ( $classname{$class} eq "NT" ) ... # set output to NT page if ( $classname{$class} eq "UNIX" ) ... # set output to UNIX page if ( $classname{$class} eq "MAIL" ) ... # set output to MAIL page ... } } #### foreach my $page (qw/NT UNIX MAIL/) { # open output html file for this page, print the header, # maybe you open a second file for the html to "#include", # then... foreach my $class (sort grep {$classname{$_} eq $page} keys %classHash ) { foreach my $status (sort keys %{$classHash{$class}}) { # print the page content, etc. } } # print the footer and close this output file(s). }