in reply to automating linux commands in perl

You say you "want the whole process to occur twice", which I assume means that you want two iterations over this sequence:

That actually looks like you're running the one process four times on each file (each set of data) in $dirname. Okay, whatever.

But if this is really what you want, you should move the "$m++" so that it is outside the while loop. Also, it would probably look more sensible if you moved the "closedir(DIR)" so that it is inside the do ... until loop.

(update: Forgot to mention: please use proper indentation -- it really does help.)