Hi Madi,<br><br>I would suggest<br><br>&nbsp; my $foo=&quot;ABC-987-01&quot;;<br>&nbsp; my ($bar) = $foo =~ m/^(.+)-\d\d$/;<br><br>This produces $bar with a value of &#39;ABC-987&#39;.<br><br>Alex<br><br><div class="gmail_quote">On Tue, Jul 8, 2008 at 11:00 AM, Madison Kelly &lt;<a href="mailto:linux@alteeve.com">linux@alteeve.com</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi all,<br>
<br>
 &nbsp;I&#39;ve got a simple problem I often come across, and I&#39;ve got a way to make it work. However, I&#39;ve always felt there must be a more ... elegant way of doing it.<br>
<br>
For example, let&#39;s say I want to copy a variable and strip a bit off the end;<br>
<br>
my $foo=&quot;ABC-987-01&quot;;<br>
my $bar=$foo;<br>
$bar=~s/(\w+-\d+)-\d+/$1/;<br>
# $bar now &#39;ABC-987&#39;.<br>
<br>
That&#39;s three lines. Is there a way to do this in one line? Specifically, is there a way to assign &#39;$1&#39; to a new variable in one go?<br>
<br>
Thanks!<br>
<br>
Madi<br>
_______________________________________________<br>
toronto-pm mailing list<br>
<a href="mailto:toronto-pm@pm.org" target="_blank">toronto-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/toronto-pm" target="_blank">http://mail.pm.org/mailman/listinfo/toronto-pm</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Alex Beamish<br>Toronto, Ontario<br>aka talexb