... my @cap = $text =~ /([a-zA-Z0-9]+)\s+[z]{15}\s+([a-z0-9]+)/g; while (@cap) { print "string: $cap[0] ... $cap[1]\n"; splice @cap, 0, 2; }