in reply to On patterns and more

Okay, first things first: What is $_? Simply put, it's a variable. In that sense, it's no different than $foo or $bar. What makes it special is that it's used it by default in many situations, if you don't supply another variable. The chomp() function, for example, which removes $/ (which is typically \n) from the end of one or more variables. If you write chomp($foo), it will affect $foo; but if you write chomp(), it will affect $_ by default.

Another example of using $_ is the foreach() loop in your own code. Foreach creates a local alias for each element in the given list. Because you didn't specify a name for that alias, it defaults to using $_. But, you could have written that as "foreach my $thisName (@myNames)", in which case the $thisName variable would be used as the alias instead.

The problem in your loop actually isn't the pattern match - that does just what you think it should, matching only strings that contain "jackson". The problem is that you've left out the curly braces. Unlike C, Perl's curly braces are always required for compound statements. So you need to write that if() like this:

if ($_ =~ "jackson") { print $_ . "\n"; }

That's only relevant when you're using a statement that requires a code block, though, as in "if() { ... }" - there are alternatives you can use that wouldn't require one, such as a logical-and operator or statement modifiers. (Note that these examples take advantage of the fact that the match operator m// also defaults to matching against $_!)

m/jackson/ and print $_ . "\n"; # logical-and print $_ . "\n" if (m/jackson/); # statement modifier
Finally (whew!) the . operator does string concatenation. That is, "foo" . "bar" will result in "foobar".