Be careful: you are heading for trouble. There are various reasons why joining in Perl will sometimes be faster than a database. One might be a poor choice of database, or an obsolete version. Another might be missing indexes or incorrect SQL. There are also many tuning options on most databases.
The most obvious thing though is that in order to do this in Perl you have to retrieve all of the records that you might possibly be interested in so that you can examine them. In any database of non-trivial size, that would be a very slow operation. In short, your in-memory approach will lose to the database as soon as the amount of data to be examined reaches a point where fetching it all from the database is too slow.