my $last_match; if ( grep { /^tag\: (.*)$/ and $last_match = $1 and 1} ) { print "Found tag: $last_match\n"; }