Try this:
#!/usr/bin/perl -w
use strict;
my( $name, $yn, @usrlst );
#read the file
open( FILE, "<users.txt" ) || die;
@usrlst = <FILE>;
close( FILE );
print "Enter your name--> ";
chomp( $name = <STDIN> );
foreach( @usrlst ) {
if( /$name/igmo ) {
print "That name has already been added";
last;
}
else {
print "Name not found. Would you like to add it? (y/n)--> ";
chomp( $yn = <STDIN> );
if($yn =~ /y/i ) {
open( OUTPUT, ">>users.txt" );
print OUTPUT $name, "\n";
close OUTPUT;
} else { print "FINE, be that way!\n"; }
}
}
print "And the boredom continues.\n";
Don't know if it'll compile...just jotted it down here in the text
editor. G'luck.