my @contents; my $header=; # extract the first line while () { next unless /\S/; # ignore whitespace only lines. last if /^done/; # finish when we hit a line starting with 'done' #chomp; # uncomment if you dont want newlines in contents. push @contents,$_; # add the line to the buffer }