$_ = q(UFOFH 33603 01231 /0000 0024/ 1024/ 2025/ 3027/ 4030/ 5025/ 6028/ 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";