my @a=(); foreach $a[0](`cat file`){ foreach $a[1](@b){ foreach $a[2](grep (/4/, @c)){ }}}