my $s = 'This is a test'; #Create an array my @words; while ($s =~ /(\w+)(?=\s+(\w+))/g){ #Push each found word into an array push @words, [$1,$2]; }