use strict; my $drive; my $count = -1; open( LIST, "tpconfig -l|" ) or die $!; while( ) # I added the ... which I suspect you had. { ($drive) = unpack '@0 A8',$_; ++$count if m/^drive/; system("tpconfig -delete -drive -index ${count}"); # You should check all system calls for error. # system will set $? to an error code for you. } #### system("tpconfig -delete -drive -index ${count} 2>nul:"); die "Unknown Error with tpconfig $count" if $? >> 8;