use strict; use warnings; # Here's where we'll keep the information on who likes what my %what_they_like; # Ask everyone what they like collect_information(); # Report the collected information report_information(); sub collect_information { print "Collecting information...\n"; while (1) { # Ask for their name print "Name: "; my $name = ; last unless defined $name; chomp $name; # Ask what vegetables they like print "Vegetables: "; my $vegetables = ; last unless defined $name; chomp $vegetables; # Remember their name and their vegetables $what_they_like{$name} = $vegetables; print "\n"; } print "\n\n"; } sub report_information { my @names = keys %what_they_like; foreach my $name (@names) { my $vegetables = $what_they_like{$name}; if ($vegetables eq '') { print "$name: --\n"; } else print "$name: $vegetables\n"; } } }