while () { $_ =~ /(\S*)/; if($it == 0 ){ $pri=$1;} else{ for($i=1; $i<=$#pattern+1; $i++) { if( $str !~ /$pattern[$i-1]/){ }else{ redo; } } } }