Yeah, there are simpler ways to keep a list of IPs. As the list grows, time to check them increases tremendously.
If you really must do it this way, use a database. Even something simple like DBD::CSV would help immensely.
Specific things in your code that I'd do differently are:
- Error checking (always check the return value of open calls!)
- Open the IP list for appending, at least. ">> listofips.txt". That way, you don't have to write the whole thing at once.
- Setting $/ to undef and slurping the whole file into a scalar instaed of using read.
But tracking IP addresses really isn't the way to go here, as
merlyn and others have pointed out.