my $string = 'this is a line with some words';
my @words = split(/\s+/,$string);
print "$_ " for @words[0..4];
will print only the first 5 words. Are you sure you want to display x number of words and not x number of characters/bytes?
[perldoc.perl.org...]