my $last_match; if ( grep { /^tag\: (.*)$/ and $last_match = $1 and 1} ) { print "Found tag: $last_match\n"; } #### while () { next unless /^tag\: (.*)$/; print "Found tag: $1\n"; } #### print map /^tag\: (.*)$/ ? "Found tag: $1\n" : (), ;