Updated scripts to use perl sub