my $script_text = 'whatever'; # list var/sub names without %$@ # ensure vars can't pop up in other contexts - eg messages my @obsf = qw (var1 var2 sub1 sub2 ...); # remove comments - note I use "# ## to denote comment # to ensure only comments get removed $script_text =~ s/\s*# ##[^\n]+\n\s*/\n/gis; # remove extraneous CRs $script_text =~ s/;\s*\n\s*/;\n/gis; # and a few other things - html tags - tidy up $script_text =~ s/>\s+