my $dir = '/path/of/dir'; opendir my $dh, $dir or die "Can't opendir '$dir': $!\n"; unlink grep s{^(.*$mypattern)}{$dir/$1}i, readdir $dh;