perl function pos

The pos function in Perl is used to get or set the current matching position of a regular expression match.

Here's an example:

my $string = "The quick brown fox jumps over the lazy dog.";
if ($string =~ /quick.*fox/g) {
    print "Match found!\n";
    my $pos = pos($string);
    print "Position of match: $pos\n";
}
Source‮:‬www.theitroad.com

Output:

Match found!
Position of match: 16

In this example, the pos function is used to get the current matching position of the regular expression match. The regular expression /quick.*fox/g matches the string quick followed by any characters, followed by fox. The g modifier is used to match all occurrences of the pattern in the string. When the match is found, the pos function is called to get the position of the match. The value of $pos is then printed to the console. In this case, the position of the match is 16, which is the index of the first character of the match in the string.