while ( $teststring =~ s/\b([a-z]+-[a-z]+-[a-z]+)\b/phrase/i ) { print $1; }