my @lines = ; # The entire file in an array my @questions = (); # A new array for questions my $tmp = ""; # A tmp variable to capture stuff in my $count = 0; foreach my $line(@lines) { if($line =~ /^===$/) { push(@questions,$tmp) unless $count == 0; $tmp = ""; next; } $tmp .= $line; } # and then to get the last one push(@questions,$tmp) if $tmp;