Yes, regex handling in Perl is the smoothest I have ever seen, and it matched the first description I heard of perl as "the best tool for text processing". I have done big things with that.
Those $ variables are dynamic scoped! If you call a method and it matches stuff you lose the variables!
My match scopes typically looked like so:
if ($inString =~ /^([ \t]+)(.*)$/) {
my $indent = $1; # store first match
my $remainder = $2; # store second match
# do stuff
}
(not tested, just edited by hand to anonymise)