http://www.perlmonks.org?node_id=1223577


in reply to Perl variables embedded in CSS in a CSS file not resolving correctly when the file is linked in

What you want is to use one of the many templating systems. See Template for a selection of those.

If you're hell-bent on rolling your own, just to keep the precious Perl variables, my suggestion is to declare them explicitly in a hash and to replace them with a tiny loop:

my %template_variables = ( 'navytext' => $navytext, # ... ); my $css = <<'CSS'; #tabmenu { color: #$navytext; } CSS sub fill_template { my( $str, $vars ) = @_; $str =~ s!\$(\w+)!$template{ $1 } || '$' . $1!ge; $str }; print fill_template( $css , \%template_variables );