#!/usr/bin/env perl use strict; use warnings; { my %father_of = get_son_to_father_map(); display_menu(); while (1) { my $menu_selection = get_menu_selection(); if ($menu_selection eq 'e') { print "Exiting ...\n"; last; } elsif ($menu_selection eq 'a') { print "Son-father pair addition.\n"; print "Enter son's name: "; chomp( my $son = ucfirst lc ); if (exists $father_of{$son}) { print "$father_of{$son} is the father of $son\n"; } else { print "Enter father's name: "; chomp( my $father = ucfirst lc ); $father_of{$son} = $father; } } else { print "Invalid menu selection! Try agin.\n"; } } print "Done!\n"; } sub display_menu { print <<'MENU'; Menu Selections =============== a - add son-father pair e - exit MENU return; } sub get_menu_selection { print "\nEnter menu selection: "; chomp( my $selection = lc ); return $selection; } sub get_son_to_father_map { return ( Jeff => 'Doug', Thomas => 'Evan', Robert => 'Jason', Bruce => 'Richard', Clark => 'Jon', ); }