Regular Expressions :: capturing data

 1        #
 2        # capture data matched by a pattern with ()
 3        # 
 4        #
 5        my $string = 'is there a 617 phone number 617-555-1212 here?';
 6    
 7        if ($string =~ m#617-(\d\d\d-\d\d\d\d)#) {
 8    
 9            print "found the 617 number: $1\n";
10    
11        } else {
12    
13            print "no 617 number found\n";
14        };
15    
16        # prints 'found the 617 number: 555-1212'