Matching a regular expression multiple times with Perl

Viewed 31635

Noob question here. I have a very simple perl script and I want the regex to match multiple parts in the string

my $string = "ohai there. ohai";
my @results = $string =~ /(\w\w\w\w)/;
foreach my $x (@results){
    print "$x\n";
}

This isn't working the way i want as it only returns ohai. I would like it to match and print out ohai ther ohai

How would i go about doing this.

Thanks

2 Answers
Related