in reply to Break out of program to get correct logic (total count)

I'm trying to fix without using subroutines

I also tried subroutines but didn't work for me

You should try using subroutines without calling exit 0; all over the place.

You can use return to exit a subroutine, but if you're dealing with a callback, as with File::Find, that won't work as find will just keep calling it, again, and again, and again, as it was designed to do.

To escape File::Find::find you'll have to use goto LABEL as in

find( ... sub { goto END_OF_FILE_FIND; } ); END_OF_FILE_FIND: print "got 20 and quit\n";

You shouldn't use backticks all over the place, make a subroutine sub do_backup { and call it.

And you don't need to use backticks for everything, use abstractions (subroutines), see hostname site:perldoc.perl.org

If I were you, I would draw draw a plain ASCII diagram or flowchart of how this program is supposed to operate , it helps in organizing the program (what is a loop, what is a function ) -- it should be a statement of what you want to accomplish, it shouldn't reflect the peculiarities of how File::Find operates