Answer:
#!/usr/bin/perl
use warnings;
use strict;
my $file = 'File1';
my $name;
my %h = ( ansy => 'Yes', ansn => 'No' );
open(Handle, '>>$file') or die $!;
while(<Handle>){
 print $_;
}
print "Do you want to enter your name ? \n";
my $answer = <STDIN>;
chomp $answer;
print "You have entered input as '$answer' \n" ;
my %h = ( ansy => 'Yes', ansn => 'No' );
if( $answer eq $h{ansy} ) {
 # if condition is true then print the following
 printf "Please enter your name ? \n";
 my $answer1 = <STDIN>;
 chomp $answer1;
 printf "Your have entered '$answer1' and it will be added to list \n";
 print Handle '$answer1';
} elsif( $answer eq $h{ansn} ) {
 # if condition is true then print the following
 printf "You have entered No and we will exit";
 exit();
} else {
 # if none of the above conditions is true
 printf "please enter either Yes or No \n";
}
close(Handle);
Explanation:
Above Code will work as per requirements. File1 is the path of your file.