my @array = qw(hey hello yes no key dog cat); foreach (@array) { if (/key/) { msg('Yes, key found'); last; # is 'last' redundant here?? } } sub msg { my ($msg) = @_; print "$msg\n"; exit; }