It seems it doesn't matter if there is a loop or not. The bug happens if the same split statement is executed several times.
[16:18] u...@debian7 ~/test/split $ cat split-func.pl
use strict;
use warnings;
use utf8;
use Data::Dumper;
binmode STDOUT, ':utf8';
sub my_split {
return (split $_[0], $_[1])[0];
}
my $split_chr = 'รค';
my $good = "x${split_chr}y";
my $bad = 'xay';
print Dumper(my_split($split_chr, $good));
print Dumper(my_split($split_chr, $bad));
print Dumper(my_split($split_chr, $good));
[16:18] u...@debian7 ~/test/split $ perl5.20.1 split-func.pl
$VAR1 = 'x';
$VAR1 = 'xay';
$VAR1 = "x\x{e4}y"; # this should be the same as the first line
---
via perlbug: queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=123469