unless(grep /home/, @words) { print $words[$x]; } #### print $words[$x] if $words[$x] =~ /home/;