if ( $string =~ m/(foobar)/ ) { $match = $1; push (@array, $match); bunch of other stuff... }