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