in reply to Re: optimise perl code
in thread optimise perl code

There's no need to escape slashes or periods within a quoted string:
... $result = "$dirname/$temp1.$temp2.$basename";
(you escape a period when you want to match a literal period character in a regex; you escape a slash if you want to match a literal slash in a regex that happens to use the common "/" delimiters, as in /dir\/path/)