use DBD::Pg; my $foo = q{foo'bar'baz}; print DBD::Pg::db->quote($foo); # prints 'foo''bar''bas'