use warnings; use strict; use open qw/:std :utf8/; use Text::Wrap 'wrap'; open my $fh, '<:raw:encoding(UTF-8)', '1.promises.txt' or die $!; local $/ = ''; local $Text::Wrap::columns = 71; while (<$fh>) { s/^\s+|\s+$//mg; if (/\A\w+\z/) { print ' ' x int( (71-length)/2 ), $_, "\n"; next; } s/\n|\s{2,}/ /g; print wrap(' 'x5, '', $_), "\n"; } close $fh;