$filename='XX-ZZ-YYYYMMDDHH' $filename =~ /^(\d{2})-(\d{2})-(\d{4})(\d{2})(\d{2})(\d{2})$/; # $1 is XX, $2 is ZZ, and so on