in reply to grep function usage

Perl grep does what Perl grep does. Perl grep is not like command line grep. Think of grep{} like a "filter" that operates on a list. If the thing within grep{$something} is TRUE, then the input is passed to the output, ie, a "filter"...THAT'S IT!

Ok, look at this:

my $t = 1; print grep {$t} qw( a b c d e ); What do you think that means? this is the same as: grep{1}qw( a b c d e ); and yields the exact same output as input list (a b c d e) grep {0} qw( a b c d e ); yields nothing! because this means foreach(a b c d e), pass each item to the output (to the left) if the thing within grep{} is true. BUT {0} is NOT true! So nothing is passed to your print. my $True_false = "False"; foreach (qw ( a b c d e )) { print if ($True_false eq "True"); print "" && $_; #another way #either way prints nothing!!! } Your very cute use of XOR is well, cute. my $t = 1; print grep {$t^=1} qw( a b c d e );
The above code "toggles" the value within the grep{} between TRUE and FALSE. So you get every other list element. Odd or even depending upon whether $t starts at 0 or starts at 1. This "how do I get the even things in the list" is cute, but maybe a bit too cute?

Anyway the code works exactly as expected.

Update: Maybe the problem is that you don't know what $t^=1 means?
$t+=1; means $t = $t + 1; #better as $t++, but no matter here..
$t^=1; means $t = $t ^ 1;