<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial,helvetica,sans-serif;font-size:10pt">Two efficient ways<br>
<br>
1. Using anchor ($) to make it match faster<br>
-&gt; perl -le '$foo="ABC-987-01"; $bar=$foo; $bar =~s/-\d+$//;print $bar'<br>
ABC-987<br>
<br>
2. Using non-regex.<br>
-&gt; perl -le '$foo="ABC-987-01"; print substr($foo, 0, rindex($foo, "-"))'<br>
ABC-987</div></body></html>