in reply to Interesting Use for "state" Variables

All you need is another pair of curlies. And it will actually work correctly, unlike the state variables.

{ my $i; foreach (@array) { do_something_with($item, $i++); }}

BTW, you should NOT use

printf " %2d. '$color'\n", $idx;
what if the $color contains some format specifiers?!? Please use
printf " %2d. '%s'\n", $idx, $color;
instead.