use warnings; use strict; use Regexp::Common qw/number/; use Data::Dump; #Debug while () { /^($RE{num}{decimal}\s*){4}$/ or die; my @cols = /$RE{num}{decimal}/g; dd @cols; #Debug } __DATA__ 1.234 5.6789 -1.235-4 1.234 5.6789-12.235-4 #### (1.234, 5.6789, -1.235, -4) (1.234, 5.6789, -12.235, -4) #### $ perl -MRegexp::Common=number -nle '$,=" ";print/$RE{num}{decimal}/g' input.txt >output.txt #### $ perl -MRegexp::Common=number -pe 's/(?>$RE{num}{decimal})\K(?=$RE{num}{decimal})/ /g' input.txt >output.txt