open(MYFILE, $data_file) || die("Could not open file!"); @raw_data=; foreach $c (@raw_data) { @c = $c; (@c[0],@c[1],@c[2], @c[3], @c[4], @c[5], @c[6])=split(/\s+/,$c); if(@c[2] eq ENERGY) { #print "energy found. reading next line\n"; while(@c[2] ne ENERGY) { $_=; print $_; $count = $count + 1; } } } print "$count\n"; close(MYFILE);