#!/usr/bin/perl #! $master = "comp.hw."; @items = ( "comp.", "comp.hw.", "comp.hw.new.", "comp.hw.hw.", "comp.sw.old.", "muse.hw.new.", "ancient." ); for ($level = 1; $level < 4; $level++) { printf("Match Level: $level\n"); # $level = no. of '.' to match @m = split(/\./, $master); $num_m = @m; $buf = ""; for ($i = 0; $i < $level; $i++) { if ($i >= $num_m) { last; } $buf .= $m[$i] . "."; } printf("Master: >%s<\n", $buf); foreach $str (@items) { if ($str =~ /^$buf/i) { printf("\t%s MATCHES %s\n", $str, $buf); } else { printf("\t%s DOES NOT MATCH %s\n", $str, $buf); } } printf("\n"); }