use File::Find; use strict; use warnings; my $x = shift; my @array; find(sub { push @array, $File::Find::name if /\.(?:h|c|sh)$/; }, '.'); my @x_files = grep {/\Q$x\E/} @array;