pseudo code or something just to illustrate what the code is doing use strict; my %hs1; #... $| =1; while(1){ chomp(<>); do something to fill %hs1 if ($_=~/X/); sleep 5; %hs1 = (); }