You don't want to know if a value is a string or number, since you're building SQL so they're always converted to strings. You want to know if the string only contains numbers digits. You should probably use DBI's $dbh->quote or placeholders. But otherwise my $is_num = $value =~ /^-?\d+(\.\d+)?$/;