$ftp->dir or die "cannot list dir contents\n"; foreach my $file2(@lines){ next if($file2 =~ m/^(d|l)/); # Skips all directories or symbolic links $file2 =~ s/^(.+ )(.+?)$/$2/; # Return jsut the filename from the string $ftp->get($file2); }