But this only returns the penultimate charcter block before the newline
The last block is followed by a newline, not a blank, while in your regex there is a space trailing the block, so it does not match. Next problem, it only returns a single block because you match the entire string at once, but capture into always the same parens. So after one single iteration you have "eaten" the entire string, but you only get the last paren content.
Update: Checking for a
UFOFH at the start of the line then splitting on blanks as suggested is a probably the easiest and most robust solution, but you can do it with just regexen:
$_ = q(UFOFH 33603 01231 /0000 0024/ 1024/ 2025/ 3027/ 4030/ 5025/ 602
+8/ 7060/ 8081/ 9098/ 0110/ 1107/ 2106/ 3102/ 4080/ 5065/ 6057/);
my @block;
if(/^UFOFH/gi) { # NB: /g is necessary for the following \G to work
my @matches = m#\G\s([/\d]{5})#g;
@block = splice @matches, 0, 27 if @matches >= 4;
}
print "@block\n";
The \G is an anchor kind of like ^, except it does not match at the beginning of the string, but at the point where the previous /g match ended. As you see, it is slightly complicated to do this without split..
Update: I have a ways yet to go, obviously. The above solution bugged me, just slightly but it did. It took a day until I realized how to do it well - or more like, slap my forehead and say "D'oh".. This is the real thing (until further notice..):
my @matches = m#(?:^UFOFH|\G)\s([/\d]{5})#g;
my @block = splice @matches, 0, 27 if @matches >= 4;
print "@block\n";
____________Makeshifts last the longest.