while ( $text =~ m!(^\s+\.com)!gi; ) { # the "g" tells Perl that this can work as a loop! print $1; # or whatever you want to do with the captured link. } #### $text =~ /a href="(.*?)"/gi; # The ? modifier after another modifier tells perl not to be greedy in the *, stopping, here, before the first \" (instead of swallowing all the string as it would with "."