This is not a Perl problem! Use the abilities of your database (a join or subselect) to find out the usernames you want. That's what databases are actually good at, after all. :)
Rest of the problem will become a piece of cake then. Problem solved.
P.S. read about the unlink-function what jwkrahnsaid. No need to shell out to "rm".