in reply to Re-use of a global match

The reason is the "g" (global) option. The "g" option means that the next search will start where the last search succeeded. There is a counter associated with the string being searched that can be accessed using the "pos" function. The search starts from "pos($regexp)". See a modified version of your code:

#!/usr/local/bin/perl use strict; use warnings; my $regexp = 'Perl Monks'; if($regexp =~ m/^Perl Monks/gi) { print "\nFound.."; } else { print "\nNot Found.."; } print "\npos = ".pos($regexp)."\n"; if($regexp =~ m/^Perl Monks/gi) { print "\nFound.1."; } else { print "\nNot Found.1."; }

when you run the code you obtain:

$ perl /tmp/prueba.pl Found.. pos = 10
Since "pos" is now 10 the regexp will not match from that position.
Try to eliminate the "g" option the second time and the regexp will succeed.