use strict; use Data::Dumper; my $str = 'The rabbits is $10 and the dogs are $20. ' . 'The phone number is 555-1212, mobile number 0404-120021'; my $animal = "rabbit|dog"; my %prices = $str =~ m/((?:$animal)s?)\s(?:is|are)\s(\$\d+)/g; my @phone = $str =~ m/(\d+-\d+)/g; print Dumper(\%prices); print Dumper(\@phone);