my @words = split; my @tags = (); # tags found at the end of this note while (my $tag = pop @words) { last if $tag !~ /^\@/; # Not a tag, bail $tag =~ s/^@//; # Trim the "@" push @tags, $tag; push (@{$lines{$tag}}, \$this_line); } #### my @tags; # tags found at the end of this note for my $tag ( reverse split ) { last unless $tag =~ s/^\@//; # Not a tag, bail push @tags, $tag; push @{ $lines{ $tag } }, \$this_line; }