how to escape dollar in unixcommand

i have

my @tmp = `egrep 'jpg$|gif$' output.txt`;


perl assumes $ as a variable;
i tried escaping but failed please help me

Try

my @tmp = `egrep 'jpg\$|gif\$' output.txt`;

Actually, I'd say it has nothing to do with Perl in that case, since egrep is an external command.
It searches for two patterns (incl. "$" regular expression, which stands for "end of line").
I hope I'm not terribly off base :smiley:

please anyone can help me in this context

1)use dollar in commands

my @tmp = `egrep 'jpg$|gif$' output.txt`

2)i want to find a $string variable in my perl program in the above command

my @tmp = `egrep 'jpg$|gif$|$string' output.txt`

please correct me where ever required please help me with this escaping stuff

Did you try psuedocoder's code?

this is the unfortunate side-effect of cobbling solutions together, but for this Perl has the handy-dandy system() family of commands executing external commands | Perl HowTo.

You'll probably need to handle it differently from what you're doing, or if you're calling this perl from a shell, maybe do a

for item in $list ;do perl.pl $item ;done 

as needed...

If you want to read from a file, do it properly. With Perl, there's almost never a need to call a standard UNIX utility externally, because the functionality is already there.

open my $file, '<', 'output.txt' or die "Can't open output.txt: $!";
my @tmp = grep { /jpg$/ || /gif$/ } map { chomp } <$file>;
close $file;