#!/usr/bin/env perl use warnings; use strict; my $x = "0.01 NaN 2.30 4.44"; # the following works as desired my $r1 = qr/([Na0-9\.\-\+]+)\s+ ([Na0-9\.\-\+]+)\s+ ([Na0-9\.\-\+]+)\s+ ([Na0-9\.\-\+]+)/x; my ($d, $e, $f, $g) = ($x =~ m/$r1/x ); print "good: $d, $e, $f, $g\n"; # recursive subpatterns my $rx = qr{ ([Na0-9\.\-\+]+) \s+ ((?1)) \s+ ((?1)) \s+ ((?1)) }x; ($d, $e, $f, $g) = $x =~ $rx or die; print "good? $d, $e, $f, $g\n"; # or match / validate first, then split my $ry = qr{ ([Na0-9\.\-\+]+) (?: \s+ (?1)){3} }x; $x =~ $ry or die; ($d, $e, $f, $g) = split ' ', $&; print "good? $d, $e, $f, $g\n";