use strict; use warnings; my @positions = qw(sitting standing reclining); my @locations = ('at the museum', 'in the woods', 'on the beach', 'in the kitchen'); my @drinks = qw(scotch beer coke yoohoo); my $flag = 1; do { my $selection = print_options( \@drinks ); $flag = do_it( $drinks[ $selection - 1 ], \@positions, \@locations ); } until $flag == 0; sub print_options { my $drinks_ref = shift; for ( my $i = 0 ; $i <= $#{$drinks_ref} ; $i++ ) { print $i + 1, "\. $drinks_ref->[$i]\n"; } print "Choose a number: "; chomp( my $selection = <> ); return $selection; } sub do_it { my $drink = shift; my $positions_ref = shift; my $locations_ref = shift; my $rand_position = $positions_ref->[ rand( $#{$positions_ref} ) ]; my $rand_location = $locations_ref->[ rand( $#{$locations_ref} ) ]; print "You just drank a $drink $rand_location in the $rand_position position.\n"; if ( $rand_location eq 'on the beach' ) { print "YEEEEEHAAAWWWWWWWWWW!\n"; return 0; } else { return 1; } }