Replace shell code with Perl function
Make imports consistent