Please read the PerlMonks FAQ and How do I post a question effectively? if you have not already done so. Your post does not contain your Perl attempt, at present it looks as though you have posted a bash script and asked someone to convert it to Perl for you.