my ( $space, $wc ); my $get_words = 5; while( read(DATA,$_,1) ) { if ( m/\s/ ) { $space = 1; } else { if ( $space ) { print "\n"; $space = 0; $wc++; last if $wc >= $get_words; } print; } } __DATA__ There was an old lady who lived in a shoe