use strict; use warnings; my ($file, $handle, @arr); open($handle, 'test.txt'); BREAKPOINT: while (<$handle>) { if (m/Here starts the second paragraph/) { chomp; push @arr, $_ for split /\s+/, $_; while (<$handle>) { chomp; last BREAKPOINT if !$_; push @arr, $_ for split /\s+/, $_; } } } print join "\n", @arr;