use strict; our $it; my @fils; foreach my $line (@fils) { if ($line =~ /aa bb cc/) { $it = 4; # do something } if ($it == "4") { # more stuff } }