my $lastname=''; #here put the return value of LDAP open( my $fh, ">:encoding(UTF-8)", "log.txt") or die $!; print $fh utf8::is_utf8($lastname) ? 'utf8 flagged,' : 'not utf8 flagged,'; print $fh $lastname; close $fh;