#!/usr/bin/perl use strict; use warnings; use utf8; use open ':encoding(utf8)'; my $ofile = 'utf_issue.txt'; open(my $fh,'>', $ofile) or die "Error opening $ofile: $!\n"; binmode($fh, ":utf8"); my $x = 'FREIGHT – INTRASTATE'; print $fh $x, "\n"; print $fh pack('A20',$x), "\n"; #### ################################################################### # This subroutine pads 'txt' on the right to length 'len'. ################################################################### sub mypack { my $len = shift; my $txt = shift; $len =~ s/^A//i; # Remove 'A' that system "pack" function uses. return sprintf("%s%s",$txt, ' 'x(($len-length($txt)))); }