#!/usr/bin/perl use warnings; use strict; use DBI; use DBD::SQLite; my $sql = DBI->connect('dbi:SQLite:dbname=1.db', q(), q()); $sql->do('create table TABLENAME (type varchar, name varchar)'); $sql->do(q(insert into TABLENAME values ('MASTER', 'm1'))); $sql->do(q(insert into TABLENAME values ('MASTER', 'Data1'))); $sql->do(q(insert into TABLENAME values ('SLAVE', 's1'))); my $sth = $sql->prepare(q(select T.Name from TABLENAME T where T.Type = 'MASTER' and not exists (select 1 from TABLENAME T2 where T2.Name = T.Name and T2.Name like 'Data%'))); $sth->execute; my $aref = $sth->fetchall_arrayref; print "@$_\n" for @$aref;