my $MaxButtons = 5; my $RemainingButtons = $MaxButtons; my $ButtonsOnPage = 0; for $key (sort keys %HashCount) { for $ele (sort keys %{$HashCount{$key}}) { if ($ele eq 0){ } else { if ($ele eq 1){ print "\\multirow{$HashCount{$key}->{0}}{0.85in}{\\mytabhead{$key}} \& " . $HashCount{$key}->{$ele} . "\n"; } else { print " \& " . $HashCount{$key}->{$ele} . "\n"; } } } }