You might be interested in
CGI::Session::PureSQL. It's not as flexible as regular CGI::Session, but it would definitely make it easier to implement your features. Since that module uses regular database columns to store session data, you wouldn't have such a hard time querying the entire sessions table.