take a look at
while(){ ... } loops in
perldoc perlsyn and
system(); grep(); sleep(); from
perldoc perlfunc
Update: Actually, in stead of system(), you'll want to capture the output .. here's a starting point for that:
Working with other processes and programs