use strict; use warnings; open my $thai_fh, '<:utf8', "thaikjv-fixed.txt" or die $!; while(<$thai_fh>){ if (/^@(...\d\d\d)/) { open my $out_fh, '>:utf8', "$1.html" or die $!; print {$out_fh} $_; } }