use DBI; my $dbh=DBI->connect('dbi:Pg:dbname=template1', 'user' , 'password', { RaiseError => 1, AutoCommit => 1 } ); # [...] sub pg_drop_if_exists { my $dbname = shift; my $sth = $dbh->prepare(q{SELECT datname FROM pg_catalog.pg_database WHERE datname = ?}); $sth->execute($dbname); if ($sth->fetchrow_arrayref()) { $dbh->do('DROP DATABASE ' . $dbname); #placeholder and quote don't work, security! } } pg_drop_if_exists('nikos_db');