open(FILE, ""); while ( ) { #### # open the file safely or complain it wouldn't open open(FILE, "<", "info") or die "Failed to open info file: $!"; while ( ) { s/\W*$//; # remove trailing whitespace next if (!$_); # skip empty lines # check that we get our match. If not, # complain and move on unless(/^(.+?) \s+ (.+?) \s+ (.+?)$/x) { print STDERR "$_ is not a valid line"; next; } my ($old, $new, $ftpdir) = ($1, $2, $3); rename $old, $new; # ftp transfer my $server = "X.X.X.X"; my $ftp = Net::FTP->new ($server, Timeout => 9000, Debug => 3); $ftp or die "$server: cannot connect: $@"; # If you don't use ~/.netrc $ftp->login ('anonymous', 'mail@adress') or die "$_: cannot logon: " . $ftp->message; # change remote directory for the first file $ftp->cwd($ftpdir); # use directory from file # Send file to ftp server $ftp->put($new) or die "$server: cannot put $new: " . $ftp->message; # Sleep for 20 minutes before processing next file. sleep (20 * 60) } #### #Expect 2 filenames and a directory path /^([\w._-] \s+ ([\w._-]) \s+ ([\w._\/-]$)/; #### /home/jarich/passwd /etc/passwd abc a b c #### $1 = "a "; $2 = "b "; $3 = "c"