Q&A > strings > How do I return the first n words of a string? contributed by Zombie Wyzelli
$str = 'yo ho ho and a bottle crumbs.
hangin and bangin in the upper-class slums.';
print join ' ', (split /\s+/, $str)[0..4];
A foolish day
Just another day
Internet cleaning day
The real first day of Spring
The real first day of Autumn
Wait a second, ... is this poll a joke?
Results (585 votes),