foreach my $x (@names) { if ( $x =~ /test$/) { print "$path_name\n"; } }