my $from; while () { my $mail = $_; chomp $mail; next unless substr($mail, 0, 6, '') eq 'From: '; $from = $mail; last; } print "Mail from : $from\n";