use strict; my $input; my %sep = ( 'title' => '::', 'element' => '>>', ); while (1) { print q(Parse? ); chomp($input = ); exit 1 if $input =~ /n(?=o)?/i; do_map(do_parse(do_start())) if $input =~ /y(?=es)?/i; print qq(Yes or no, dumbass.\n); } sub do_start { print qq(File: ); while ($input = ) { chomp; -r $input and last; print qq(That isn't a file.\nFile: ); } return 1; } sub do_parse { die unless shift; # should never die here <.< open(FILE,<$input) or die; # same as above my (@raw,%hash,$last); push(@raw,chomp($_)) while ; close(FILE) or die; # may die here, whatever foreach my $val (@raw) { if ($var =~ /^$sep{'title'}/i) { $var =~ s/^$sep{'title'}(.*)/$1/i; $last = $var; $hash{$last} = []; next; } push(@{$hash{$last}},$var) } return \%hash; } sub do_map { my $hash = shift; map { print qq(\u$_ tables:\n); foreach my $dl (@{$hash->{$_}} { print q( ) x length $_, q( ); print $dl; } } keys %$hash; }