$pathchrs => '[-\/\.[:alnum:]_]'; $target = 'aclocal' while(<>){ /(\/$pathchrs*$target$path*)/o && print "$1\n"; }