open my $tf, "output.txt" or die "Cannot open file"; while(my $line = <$tf>) { if ( $line =~ /.*versions are SAME.*/) { # ... } }