foreach my $index ( 0 .. $#hosts ) { if ( $hosts[ $index ] =~ /$ARGV[0]/ ) { print $hosts[ $index ]; delete $hosts[ $index ]; } }