sub _d { my ($s) = @_; utf8::downgrade($_); $s } $dbh->do("SET NAMES cp1252"); my $sth = ...; $sth->execute(_d($encoded));