Pass it on the command line, and it will be available in @ARGV
:
for d in 1 2
do
perl -lne 'BEGIN {$d=shift} print "$d: OK" if /hdisk$d\s+/' $d someFile
done
Note that the shift
operator in this context removes the first element of @ARGV
, which is $d
in this case.