use strict; use warnings; use Carp qw( Carp ); use Parse::RecDescent qw( ); $|=1; my $GlobalConfigMode = <<'__EOI__'; { use strict; use warnings; my %iftypes = map +($_=>1), qw( fa gigabit atm ); } parse : Interface /\Z/ { $item[1] } Interface : iftype module '/' slot { [ @item[0,1,2,4] ] } iftype : /\w+/ { $iftypes{$item[1]}||undef } { $item[1] } | module : /\d+/ { $item[1] } | slot : /\d+/ { $item[1] } | __EOI__ my $ifparser = Parse::RecDescent->new($GlobalConfigMode) or croak "Could not create command parser"; while () { chomp; if ($ifparser->parse($_)) { print "$_ \t success\n" ; } else { print "$_ Command not found\n"; } print "------------------\n"; }