my $found; for (@list) { last if $found = /pattern/; } if (!$found) { open FILE, "> $filename"; close FILE; }