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


in reply to saving matching pattern with flip-flop operator

You could use $1, but I expect problems with retained old values if the regex didn't match.

So I prefer to directly, explicitly capture the captured value. Like this:

while (<>) { if(/START/ ... (my($time) = /END TIME (.+)/)) { unless(defined $time) { next if /START/ || /^\s*$/; print; } else { print "End time at $time\n"; } } }
BTW | is for bitwise or; you (ought to) want either or or ||.