$/ = '---------End Data--------\n'; # or whatever while (<>) { if (/name\s+-+\s+(.*)/) { # "\s+" matches "\n", "(.*)" doesn't $whatIwant = $1; # do something with $whatIwant... } }