in reply to regex man they are tough

It occurred to me that the snippet I posted, even if it does what you want, it probably it doesn't tell you much about why yours is not working, so here are just a couple of comments on your regexps. The /m modifier is useful only if you are matching a string that contains multiple lines; it tells perl to match ^ and $ to the beginnings and ends of lines. Study this example and you will see what I mean:

use strict; use warnings; my $string = "foo\nbar\nbaz\n"; print "1st match ", $string =~ /^bar/ ? "succeeded\n" : "failed\n"; print "2nd match ", $string =~ /^bar/m ? "succeeded\n" : "failed\n"; print "3rd match ", $string =~ /bar$/ ? "succeeded\n" : "failed\n"; print "4th match ", $string =~ /bar$/m ? "succeeded\n" : "failed\n"; __END__ 1st match failed 2nd match succeeded 3rd match failed 4th match succeeded
Next, the /g modifier makes sense only if you are matching the same string multiple times want to match the same regexp multiple times in the same string. For example, using the same string as for the example above:
while ( $string =~ /(a\w+)/g ) { print "$1\n"; } __END__ ar az
Lastly, the expression $i =~ s/.//gm simply sets $i to the empty string (in this case the /m modifier does nothing; you'd get the same result without it). I don't think this gets you anything, but if that's what you wanted to do, it is simpler to just assign the empty string: $i = ''.

Update: Corrected sloppy wording. Thanks to Roy Johnson.

the lowliest monk

Replies are listed 'Best First'.
Re^2: regex man they are tough
by Roy Johnson (Monsignor) on Apr 28, 2005 at 18:08 UTC
    the /g modifier makes sense only if you are matching the same string multiple times
    Not entirely true. In scalar context (such as when it's the conditional of a while), it's about repeated matching. In list context, it will do the global match and return all the captures at once.
    $_ = 'pig dog goggles'; my @hits = /g/g; print "@hits\n";

    Caution: Contents may have been coded under pressure.