$choice = lc $choice; # ... later ... if ($choice eq 'l') #### my $filename = 'birthday.db'; # ... later ... open IN, $filename || die "Cannot read '$filename': $!\n"; print ; close IN; #### use constant CHOICE_LIST => 'l'; my $db_file = 'birthday.db'; # ... later ... if ($choice eq CHOICE_LIST) { open(IN, $db_file) || die "Cannot read '$db_file': $!\n"; print ; close IN; } #### if ($choice eq CHOICE_MODIFY) { # Use a hash, not an array. The assumption here is that the names will be unique. open(IN, $db_file) || die "Cannot read '$db_file': $!\n"; my %birthdays = map { chomp; split ':' } ; close IN; # Print out a list of the names and birthdays print "$_ => $birthdays{$_}\n" for sort keys %birthdays; print "Enter record to modify: "; chomp ($key = ); print "(M)odify or (D)elete? "; chomp ($choice = ); $choice = lc $choice; if ($choice eq 'm') { print "Enter person's birthday: "; chomp ($date = ); $birthdays{$key} = $date; } elsif ($choice eq 'd') { delete $birthdays{$key}; } open OUT, $db_file || die "Cannot overwrite '$db_file': $!\n"; print OUT "$_:$birthdays{$_}\n" for keys %birthdays; close OUT; }