#!/local/bin/perl -w

#Example: Finding the first list element that passes a test
use strict;

my @array = (50, 10, 24, 8, -2, 45, 90, -1);

my $match;     # my($match, $found, $item); works too
my $found;
my $item;

foreach $item (@array) {
   if($item < 0 ) {
       $match = $item;   
       $found = 1;
           last;      # like break in C
   }
}

if($found) {
  print "The first value in the array less than 0 is $match\n";
} else {
  print "All values of the array were greater than 0\n";
}

