http://www.perlmonks.org?node_id=812017


in reply to Better way to get the results of grep()?

Rather than using an intermediate array and saving its first element, you could save the first element from the list that grep produces.
($curFrom) = grep(/^From:/, @header); ($curSubject) = grep(/^Subject:/, @header);
Note that using the 'o' modifier on the regular expression does not offer a benefit in this instance. It is only useful when the regular expression would be re-evaluated on each execution (as when it includes a variable).