my $pathre = qr/\/$pathchrs*$target$path*/; while(<>) { print "$1\n" for /($pathre)/g; }