# pos1 - Find the first character of succesive matches 
# of a string in a line of text.
# 
# finding out exactly what the regex function pos does?????
# It'll give you the position *after* what you're looking for
# if you do iterative global regex matches, so subtract the size of the
# character matched and you'll get the position of the first character
# matched, here's the case exact matching a single string "goblin".

$line = "Once upon a time, far off in a land of fairies and goblins there lived a very cruel goblin, this goblin had a particularly ugly wart on the end of his nose...";
#                                                                                                            1111111111111111111111111111111111111111111111111111111111111      
#                  1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000111111111122222222223333333333444444444455555555556
#        01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 

$regex = "goblin";
$lenregex = length($regex);
print "regex: $regex\n";
print "length of regex: $lenregex\n\n";

$line =~ /$regex/g;
while ($after = pos($line)) {
   $first = $after - $lenregex;
   print "First character of \"$regex\" is *", $first,"*\n";
   $line =~ /$regex/g;
}
exit;


# Based on line from Perl Cookbook
#$story =~ /goblin/g;
#print "The position in \$story is *", pos($story),"*\n";

    Source: geocities.com/soho/square/Square/3472

               ( geocities.com/soho/square/Square)                   ( geocities.com/soho/square)                   ( geocities.com/soho)