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. }