#!c:\perl\bin\perl.exe use strict; use warnings; my @comments; my $i; my $j = 0; my $found_comment = 0; my $input = 'c:\yourdirectoryhere\sample_perl_data1.txt'; my $line; open(IN, $input) or die("Can't open file - $input: $!"); while($line = ) { if($line =~ m/^=/) { if($line =~ m/^===Comments===/) { $found_comment = 1; if(! defined $i) { $i = 0; } else { $i++; } $comments[$i] = ""; # initialize new comments array elements } else { $found_comment = 0; } } else { if($found_comment == 1) { $comments[$i] = $comments[$i] . $line; } } } close(IN) or die("Unable to close file - $input: $!"); #print output with a separator line between each element for($j=0; $j<=$i; $j++) { print("comments[$j] = $comments[$j]"); print("------------separator-------------------\n"); }