use strict; open IN, "filename" || die "Couldn't open file!"; my $line,$i; my $n = 5; #how many lines after the **line** to get my $emailtext = ""; while( chomp($line = ) ) { #if line has ** in it, then get next n lines if( $line =~ /\*\*/) { for my $i (1..$n) { $emailtext .= ; } #send your email here } }