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