in reply to File input not working properly?

Your loop needs to be more like
while ( my $line = <$fh> ) { chomp $line; my ( $name, $passwd ) = split /:/, $line; next unless $name eq $userName; .... }

You mak also want to look at Term::ReadKey or IO::Prompt for the password prompt