Regular Expressions   «Prev 

Perl m modifier

The m modifier treats the string as multiple lines. This allows you to use ^ and $ on either side of a newline within a string (instead of just at the start and end of the string).
For example, this program will print the first word of every line in a file:

#!/usr/bin/perl -w
$string = '';
# put the whole file in $string
while(<>) { 
 $string .= $_ 
}
while($string =~ /^\S+/mg){ 
 print "[$&] " 
}
print "\n";