#!perl use warnings; use strict; my %atoms; my $key; while() { chomp; next if /^\s*$/; if(/^[^\s]/){ s/:.*$//; $key = $_; print "\$_: $_\n","\$key: $key\n"; } else{ s/^\s*|\s*$//g; (my $sub, my $idx,my $x, my $y,my $z) = split(/\s+/,$_,5); print "\t\$_: $_\n","\t\$sub: $sub\n\txyz",join(", ", ($x, $y, $z)),"\n"; $atoms{$key}{$sub} = [ (+$x, +$y, +$z)]; # force numerical context } } __DATA__ HELIX1: x y z A 1 -1.115 8.537 7.075 B 2 -2.745 5.280 7.165 C 3 -0.777 3.267 7.329 D 4 1.610 5.225 10.885 E 5 0.296 5.263 10.912 HELIX2: K 1 -0.696 13.041 22.357 L 2 1.152 11.081 23.082 M 3 2.200 17.590 18.424