my %hash = ( polygon => { abc => ["0, 0, 10, 0, 12, 2", "10, 10, 20, 10, 22, 12",], def => ["3, 5, 3, 8, 7, 10"], }, rectangle => { abc => ["-10, -10, 20, 20"], def => ["22, 33, 44, 44", "1, 1, -3, -6"], } ); #### for my $shape (sort keys %hash) { for my $class (sort keys %{$hash{$shape}}) { print < LINE } }