foreach (@data) { my $match = $_ if /testdir/; } #### foreach (@data) { my $match = $_ if /^\//; }