if ($sentence =~ /foo/gis) { my $final_test = $sentence; if ($final_test =~ /bar/gis) { # *now* do something with the sentence... } }