the %ENV hash contains environment variables. check it with something like
if( defined $ENV{BASE_ID} ) { ...do something... }. you'll also need to set up a list of tags you're looking for, like
my @tags = qw/ $BASE_ID$ $REVISION_ID$ /;. search the file and match against your tags (you'll probably need
quotemeta for that. if you find a valid tag, and the environment variable exists, replace it with the value of the environment variable.
i hope that helps. if you have trouble coding a solution, post your code, and we'll gladly help.
~Particle *accelerates*