use warnings; use strict; use Data::Dump qw/dd pp/; while ( my $tag = ) { chomp($tag); next unless $tag =~ /\S/; # skip blank lines if ( my ($id) = $tag =~ /]+)>/ ) { $id =~ s/\W+//g; print pp($tag)," -> ",pp($id),"\n"; } else { warn "Couldn't match ".pp($_) } } __DATA__ Text... Text... Text... Text... Text... Text... Text... Text... Text... Text...