#!/usr/bin/perl -w use strict; open (FILE, "+ "; chomp ($name = ); while () { chomp; if (/^$name/) { print "Your name was already found\n"; exit; } } print "Name not found. Would you like to add it? (y/n)--> "; chomp ($yn = ); if ($yn eq 'y') { print FILE "$name\n"; #Since we went through the file we can now print to the end of the file close FILE; #Closing a file will unlock it }else { print "FINE!\n"; ; } print "end.\n";