use strict; use warnings; my $temp = "DATA\nFile\nHello\nAnother line\n"; my $found; if( $temp =~ m/File\n(^.*$)/m ) { $found = $1; print $found, "\n"; } #### my @lines = split /\n/, $temp; foreach my $idx ( 0 .. $#lines ) { next unless $lines[ $idx ] =~ m/File/; $found = $lines[ $idx + 1 ]; print $found; last; }