use Encode qw( encode ); $str = '

foo

'; for (1..5) { print("$str\n"); $str = encode('UTF-8', $str); }