<p>I'm trying to insert a comment character into a string something similar to this:</p>

<pre><code>-CreateVideoTracker VT1 "vt name"
</code></pre>

<p>becomes</p>

<pre><code>-CreateVideoTracker VT1 # "vt name"
</code></pre>

<p>The VT1 word can actually be anything, so I'm using the regex</p>

<pre><code>$line =~ s/\-CreateVideoTracker \w/\-CreateVideoTracker \w # /g;
</code></pre>

<p>which gives me the result:</p>

<pre><code>-CreateVideoTracker w #T1 "vt name"
</code></pre>

<p>Is there any way to do this with a single regex, or do I need to split up the string and insert the comment manually?</p>

```
```
$line =~ s/^(\-CreateVideoTracker)\s+(\w+)/$1 $2 #/;
```
```
The bracketed expressions (known as "capture buffers") in the first half of the regexp are referenced as
```
$1
```
,
```
$2
```
. etc in the second half.