sub print_sub_menu { my %sub_menu = %{(shift)}; my $i = 1; my $index = $i; #index of the hash #get every item of the input-hash #needs $index for cases, where not every number has a corresponding value for ($i; $i < keys(%sub_menu); $i++) { while (! exists $sub_menu{$index}) { $index++; } print "\t$index - $sub_menu{$index}\n"; $index++; } #<-- beanstandete Zeile return 0; }