You can make your scale better (to a file
with a large number of names) by employing some sort of DB.
In this case it also makes the code shorter.
Here's your program using a tied hash to a SDBM file.
All the modules you should need to do this are included with
the perl install.
use Fcntl;
use SDBM_File;
my %db_names;
tie (%db_names, 'SDBM_File', './names.db', O_RDWR | O_CREAT, 0666);
print "Enter your name--> ";
chomp (my $name = <STDIN>);
if(defined $db_names{$name}){
print "Your name was already found\n";
}else{
print "Name not found. Would you like to add it? (y/n)--> ";
chomp (my $yn = <STDIN>);
if ($yn eq 'y') {
$db_names{$name}=1;
}
}
untie %db_names;