sub does_table_exist { my ($dbh,$table_name) = @_; my $sth = $dbh->table_info(undef, 'public', $table_name, 'TABLE'); $sth->execute; my @info = $sth->fetchrow_array; my $exists = scalar @info; return $exists; } foreach my $table ('foo', 'bar', 'items') { if (does_table_exist($dbh, $table)) { print "table $table exists\n"; } else { print "table $table does not exist\n"; } }