$str = "()"; if( $str =~ s//(?{ print $1 })<\/ref>/ ){ print "Match was found." . "\n"; } print $str . "\n";