Use modules like Devel::Cycle to check for circular references. And never do stuff like:
$this->{stuff} = $this;
Bad examples of code that does this are Mail::SpamAssassin, Mail::Audit (now unmaintained), etc.
So the regex is only compiled once. This can't be done when
the regex depends on a variable, like in:
m/some stuff \d $text/
So it's better to make regex static whenever possible. Even if you have
to check against a group of regexps.
This is bad:
$filename =~ m/^stuff this and that$/o # check if filename
is "stuff this and that". *WRONG*
Filename could be: "stuff this and that\n" and "stuff this and that".
Newline is a valid character in filenames.
While this is good: $filename =~ m/\Astuff this and
that\z/o
Also filenames can have spaces and regexp metacharacters, so if you have the filename stored in a variable and want to check that in a regex, disable metacharacters before the variable read on.
As I was saying previously, a filename like:
$fname = "stuff priced at 50.xml";
When used in a regex like:
$file =~ m/\A$fname\z/;
Would match "stuff priced at 509xml" and "stuff priced at 50-xml", so
you have to do it like:
$file =~ m/\A\Q$fname\E\z/
Use it early and keep your code clean. Reduce the use of global variables.