#!/your/perl/here use strict; use warnings; use Benchmark qw(:all); use List::Util qw/shuffle/; my @words = 'a'..'g'; # create random pathnames my @paths; for (1..(shift or 1000)) { @words = shuffle(@words); push @paths, 'C:\\' . join '\\', @words[0..rand(@words)]; } # original, for test purposes #my @paths = ( # 'C:\\foo\\bar\\baz', # 'C:\\foo\\bar', # 'C:\\car', # 'C:\\c' # ); my $t0 = new Benchmark; my @nested = grep { my $candidate = $_; grep $candidate =~ /^\Q$_\E\\/, @paths } @paths; my $t1 = new Benchmark; print "$_\n" for @nested; print "Processing Time:", timestr(timediff($t1,$t0)), "\n"; exit;