my @arrvar = ; map { if ($arrvar[$_] =~ /you have to read the fourth line/) { print "$arrvar[$_+4]"; } elsif ($arrvar[$_] =~ /you have to read the second line/) { print "$arrvar[$_+2]"; } }0..$#arrvar;