in reply to Re^2: Repeating the same command in different portions of input
in thread Repeating the same command in different portions of input

Yes, splitting the 'chunk' is a good solution! However, since you've noticed the chunk lacks newlines, change:

my @values = split('\n', $chunk);

to

my @values = split /\s+/, $chunk;