my $a = 'first second ...other non-\w char groups...'; my @s; while (... not finished string ...) { if ($a =~ /\G(\w+) ?/gc) { push @s, $1; } elsif ... other stuff not important }