#!/usr/bin/perl -- use strict; use warnings; use Path::Tiny qw/ path /; for my $infile ( glob "*.dat" ){ my $outfile = "$file.bak" ; path( $infile )->copy( $outfile ); }