if ($lastHeading eq 'MEANINGLESS TEXT') { print $lines[2]; # third line print $lines[5]; # sixth line print $lines[7]; # eighth line } elsif ($lastHeading eq 'ALTERNATIVE TEXT') { print $lines[3]; # fourth line print $lines[5]; # sixth line print $lines[7]; # eighth line