Input two variable on single line

Can we input two variable on single line that separate by space example user input "list jpg" it will list all jpg files in current directory

 
echo "list jpg" | while read extn1 extn2; do ls -l *$extn2; done # will list only jpg files

Sorry I mean in Perl

 
$ cat test.pl 
#!/usr/bin/perl
$files = "list jpg";
@patterns = split(/ /,$files);
@files = <*$patterns[1]>;
foreach $file (@files) {
   print $file . "\n";
} 
 
1 Like