my $text = "aaa"; while ($text =~ m/a/g) { last } # only executes once pos($text) = 0; # $text .= ''; # another way to do it print "matched\n" if ($text =~ m/aaa/g)