Using split, an anonymous list, and pattern matching
while(<DATA>){
($name, $phone, $address) = split(":", $_);
print $name if $phone =~ /408-/ # Using the pattern matching operator
}
__DATA__
A:111-444-6677:12 Main St.
B:222-222-1234:234 main Ln.
C:408-567-4444:3456 Mary Way
D:555-234-5678:8880 Main St.
E:333-444-6556:54 Main Ln.
F:444-333-7654:123 4th Ave.
Related examples in the same category