#!/usr/bin/perl -w use strict; my $text = do { local $/; }; $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)