use Encode; use DBI; # (or whatever you use for your PostgreSQL) my $dbstr; # suppose this holds "unicode" data from the DB # ... do whatever it takes to fetch a value into $dbstr; # since DBI might not be "unicode-aware", you may need to # coerce perl into treating the value as unicode: my $unistr = decode( 'utf8', $dbstr ); my $latin1str = encode( 'iso-8859-1', $unistr ); print $latin1str; #### # snippet to convert utf8 to latin1 -- NB: only works for utf8 # characters that correlate to unicode \x{0000} - \x{00ff} # (and you really should figure out how to convert using a module) my @bytes = unpack C*, $_; # break utf8 string into bytes $_ = ''; while ( @bytes ) { my $b = shift @bytes; if ( $b & 0x80 ) { # start of utf8 (latin1) character my $c = ( $b & 3 ) << 6; # 1st utf8 byte carries top 2 latin1 bits $_ .= chr( $c | ( shift @bytes & 0x3f )); # 2nd byte has the other 6 bits } else { $_ .= chr( $b ); # utf8 ascii is just ascii. } } # now $_ holds latin1 (single-byte, iso-8859-1) characters