$date = "YYYYMMDD"; $date =~ s/(.{4})(.{2})(.{2})/$1-$2-$3/; # Yeah, you can save a few chars. But I find this clearer.