It sounds like you're more interested in the utmp and wtmp databases. check them out! (They'll tell you whose on or off and when so you can scrap your Perl script. That is, of course, unless you are using the world's most intrusive and pointless operating system!)
Comment on Re: checking file everytime a new line is added to file