require "cacheout.pl"; while (<>) { $filename = (split(/:/,$_))[3]; # Or whatever. if ($filename ne $lastfilename) { &cacheout($filename); $lastfilename = $filename; } print $filename $_; }