$file = "10abc.txt"; $from = "(\\d\\d).+?(\\.\\w+)"; $to = '$1$2'; $to = "qq#$to#"; $file =~ s/$from/$to/gee; print $file, "\n";