use strict; use warnings; my @x = ("aaBxyz", "..Bxys", "bbxyzzy", "xxAx"); # for each element in the array @x, # pass that element to the array @result if # if the 3rd character is either A or B # followed by at least one character. my @result = grep {/^..(A|B)./}@x; print "$_\n" for @result; =prints aaBxyz ..Bxys xxAx =cut #### #ok, with a weird example of $1 @result = grep{ print "$1 $_\n" if /^..(A|B)./; /^..(A|B)./}@x; =prints B aaBxyz B ..Bxys A xxAx =cut @result is the same as above # grep {} executes the code within the brackets and passes the input # to @result depending upon the true/false value of the last statement.