use DBI; my $dbh=DBI->connect('DSN info here'); my $string="D'ith"; my $val_to_put_in_mysql=$dbh->quote($string);