use strict; my $str="a b c d"; if(my($a,$b,$c,$d) = $str =~ m/(\S)\s(\S)\s(\S)\s(\S)/) { print $a,"\n",$b,"\n",$c,"\n",$d; }