my @question; sub make_question { my ($question,@answer) = @_; [ $question, \@answer ]; } push @question, make_question 'What is an example of autovivification in Perl?', '***my %x; $x{y}->[2]->{jum} ;', 'sub y { my ($self,$x) = @_ }', 'my $end = ($end > rand) ? $end : rand;'; ; for (@question) { printf "Question %d: %s\n", ++$count, shift @$_; my $HAIR = '^([*]){3}'; my $count; for my $answer (@{$_->[0]}) { if ($mode eq 'key') { if ($answer =~ /$HAIR/) { $answer = $1; } else { $answer = ''; } } else { $answer = s/$HAIR//; } printf "\t%d. %s\n", ++$count, $answer; } print "\n"; }