#better way use strict; @matches = /(foo)(bar)(baz)/; if( $bar ) { return $matches[$bar]; }