use strict; use warnings; use Data::Dumper; my @sections; while () { chomp; if (/===Comments===/../^[^=]/) { if (/===Comments===/) { push @sections,[] } else { push @{$sections[-1]}, $_ if $_ } } } print Dumper(\@sections); #### $VAR1 = [ [ 'User comments are added here. A user may write whatever they may wish.' ], [ 'Comments are related to the microarray data here.' ], [ 'Comments related to the pathway information here.' ] ];