in reply to Need to return the first occurance of a search
The distinguishing factor is that a hyphen and a digit follow the name you are looking for.
use strict; use warnings; my @array1 = qw/ cups-1.5.2-9.fc16.x86_64 cups-libs-1.5.2-9.fc16.x86_6 +4 cups-1.5.2-9.fc16.x86_64/; my @array2 = qw/ cups-libs-1.5.2-9.fc16.x86_64 cups-libs-1.5.2-9.fc16. +x86_64 /; my $pattern = "cups"; print "Array1:\n", join "\n", grep { /^$pattern\-\d/ } @array1; print "\nArray2:\n", join "\n", grep { /^$pattern\-\d/ } @array2;
|
|---|