changed awk to perl for string length count