Because at least one of your character codes is 255 or higher, your string will internally be encoded in UTF-8. However, Perl's pure string manipulation routines work transparently, whether a string is in UTF-8 or in a single byte encoding, such as split, chr, ord, length. So you can achive what you want by using rather classic code — meaning it doesn't look like anything special:
for my $i (0 .. length($str)-1) { print " " if $i; print ord substr $str, $i, 1; } print "\n";
or, like Juerd mentioned:
print join " ", map ord, split //, $str; print "\n";

n.b. For some mysterious reason, the latter code works as it should in perl 5.8.4, but fails in 5.6.1. It smells like a Unicode related perl bug.

Malformed UTF-8 character (unexpected non-continuation byte 0x00 after + start byte 0xc9) in ord at test.pl line 6. Malformed UTF-8 character (unexpected continuation byte 0xbc) in ord a +t test.pl line 6. Malformed UTF-8 character (unexpected non-continuation byte 0x00 after + start byte 0xc5) in ord at test.pl line 6. Malformed UTF-8 character (unexpected continuation byte 0xbf) in ord a +t test.pl line 6. 66 0 0 105 0 0

If, OTOH, you choose to use pack/unpack, it'll work on the raw bytes, so it will make a difference whether the string is in single-bye encoding (each character is a byte), or in UTF-8.

print join " ", unpack "C*", $str; print "\n";

In reply to Re: String to UTF-8 by bart
in thread String to UTF-8 by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.