Are you sure you need to do this? "Meaningful" ID numbers have a lot of shortcomings. However, if you really do...
Are you using a database? If so, create your own auto-increment table and just update it when you need a new number. This table doesn't have to generate the whole ID, just the numeric portion. If the numbers form part of a single sequence, then you only need a single row, e.g.:
HAM-001
HAM-002
SPAM-003
WOOF-004
If OTOH you need a separate sequence for each ID, then create one row for each prefix, i.e.
create table sequences
(
prefix text,
number int
); // etc
If you don't have a database, you'll have to emulate all the above using files.