use strict; my @depts=qw/dept1 dept2 dept3/; for(@depts){ system("grep $_ weblog >> $_.log"); }