in reply to variables in global match in regex
#!/usr/bin/perl -w use strict; my $text = do { local $/; <DATA> }; $text =~ s/my.*?\((\w+)\)/print "$1\n"; $1/ge; __DATA__ my dog is (red1) my cat is (blue1) my dog is (red2) my cat is (blue2) my dog is (red3) my cat is (blue3) my dog is (red4) my cat is (blue4) my dog is (red5) my cat is (blue5) my dog is (red6) my cat is (blue6)
red1 blue1 red2 blue2 red3 blue3 red4 blue4 red5 blue5 red6 blue6
|
|---|