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"; }