#!/usr/bin/perl use strict; use warnings; use File::Find; my $dir = shift; #dir = the argument given on the command line (./filechng.pl testdir) find(\&change_ext_if_file, "$dir"); #loops through dir scooping up all it finds sub change_ext_if_file { #called function my @files = @_; #creates array foreach my $file (@files) { ##loops through the array @files and places each file into scalar $file if ((-f $file) && ($file =~ /pdf$/)) { #checks if file and if ends with pdf $file =~ s/pdf/doc/; #replaces pdf with doc } } }