my $data= qq{cfg_a\ncfg_b[2:0]\ncfg_c[4:0]\ncfg_d\n}; ... ... open my $fh, '<', \$data or die qq{opening string by reference: $!};