my @match; while (<>)) { my @caps = /pat/ or next; @match = @caps; } if (@match) { print("Captured @match\n"); } else { die("No match\n"); }