$filename = 'FileName'; #any filename $string = 'FileName.089-09_08_45'; $string =~ s/^$filename\.(\d{2})\d/$1/; print $string; output: 08-09_08_45